Skip to content

Commit 8af9972

Browse files
author
git apple-llvm automerger
committed
Merge commit '207ecd684cc6' from llvm.org/release/18.x into stable/20240123
2 parents c19094b + 207ecd6 commit 8af9972

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

llvm/include/llvm/Object/COFFImportFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
namespace llvm {
2727
namespace object {
2828

29+
constexpr std::string_view ImportDescriptorPrefix = "__IMPORT_DESCRIPTOR_";
30+
constexpr std::string_view NullImportDescriptorSymbolName =
31+
"__NULL_IMPORT_DESCRIPTOR";
32+
constexpr std::string_view NullThunkDataPrefix = "\x7f";
33+
constexpr std::string_view NullThunkDataSuffix = "_NULL_THUNK_DATA";
34+
2935
class COFFImportFile : public SymbolicFile {
3036
private:
3137
enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };

llvm/lib/Object/ArchiveWriter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ static bool isECObject(object::SymbolicFile &Obj) {
677677
return false;
678678
}
679679

680+
bool isImportDescriptor(StringRef Name) {
681+
return Name.starts_with(ImportDescriptorPrefix) ||
682+
Name == StringRef{NullImportDescriptorSymbolName} ||
683+
(Name.starts_with(NullThunkDataPrefix) &&
684+
Name.ends_with(NullThunkDataSuffix));
685+
}
686+
680687
static Expected<std::vector<unsigned>> getSymbols(SymbolicFile *Obj,
681688
uint16_t Index,
682689
raw_ostream &SymNames,
@@ -704,6 +711,10 @@ static Expected<std::vector<unsigned>> getSymbols(SymbolicFile *Obj,
704711
if (Map == &SymMap->Map) {
705712
Ret.push_back(SymNames.tell());
706713
SymNames << Name << '\0';
714+
// If EC is enabled, then the import descriptors are NOT put into EC
715+
// objects so we need to copy them to the EC map manually.
716+
if (SymMap->UseECMap && isImportDescriptor(Name))
717+
SymMap->ECMap[Name] = Index;
707718
}
708719
} else {
709720
Ret.push_back(SymNames.tell());

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ template <class T> static void append(std::vector<uint8_t> &B, const T &Data) {
108108
}
109109

110110
static void writeStringTable(std::vector<uint8_t> &B,
111-
ArrayRef<const std::string> Strings) {
111+
ArrayRef<const std::string_view> Strings) {
112112
// The COFF string table consists of a 4-byte value which is the size of the
113113
// table, including the length field itself. This value is followed by the
114114
// string content itself, which is an array of null-terminated C-style
@@ -171,9 +171,6 @@ static Expected<std::string> replace(StringRef S, StringRef From,
171171
return (Twine(S.substr(0, Pos)) + To + S.substr(Pos + From.size())).str();
172172
}
173173

174-
static const std::string NullImportDescriptorSymbolName =
175-
"__NULL_IMPORT_DESCRIPTOR";
176-
177174
namespace {
178175
// This class constructs various small object files necessary to support linking
179176
// symbols imported from a DLL. The contents are pretty strictly defined and
@@ -192,8 +189,9 @@ class ObjectFactory {
192189
public:
193190
ObjectFactory(StringRef S, MachineTypes M)
194191
: NativeMachine(M), ImportName(S), Library(llvm::sys::path::stem(S)),
195-
ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()),
196-
NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {}
192+
ImportDescriptorSymbolName((ImportDescriptorPrefix + Library).str()),
193+
NullThunkSymbolName(
194+
(NullThunkDataPrefix + Library + NullThunkDataSuffix).str()) {}
197195

198196
// Creates an Import Descriptor. This is a small object file which contains a
199197
// reference to the terminators and contains the library name (entry) for the

llvm/test/tools/llvm-lib/arm64ec-implib.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ARMAP-NEXT: #funcexp in test.dll
1616
ARMAP-NEXT: #mangledfunc in test.dll
1717
ARMAP-NEXT: ?test_cpp_func@@$$hYAHPEAX@Z in test.dll
1818
ARMAP-NEXT: ?test_cpp_func@@YAHPEAX@Z in test.dll
19+
ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
20+
ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
1921
ARMAP-NEXT: __imp_?test_cpp_func@@YAHPEAX@Z in test.dll
2022
ARMAP-NEXT: __imp_aux_?test_cpp_func@@YAHPEAX@Z in test.dll
2123
ARMAP-NEXT: __imp_aux_expname in test.dll
@@ -28,6 +30,7 @@ ARMAP-NEXT: __imp_mangledfunc in test.dll
2830
ARMAP-NEXT: expname in test.dll
2931
ARMAP-NEXT: funcexp in test.dll
3032
ARMAP-NEXT: mangledfunc in test.dll
33+
ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
3134

3235
RUN: llvm-readobj test.lib | FileCheck -check-prefix=READOBJ %s
3336

@@ -107,6 +110,8 @@ EXPAS-ARMAP-NEXT: #func1 in test.dll
107110
EXPAS-ARMAP-NEXT: #func2 in test.dll
108111
EXPAS-ARMAP-NEXT: #func3 in test.dll
109112
EXPAS-ARMAP-NEXT: #func4 in test.dll
113+
EXPAS-ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
114+
EXPAS-ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
110115
EXPAS-ARMAP-NEXT: __imp_aux_func1 in test.dll
111116
EXPAS-ARMAP-NEXT: __imp_aux_func2 in test.dll
112117
EXPAS-ARMAP-NEXT: __imp_aux_func3 in test.dll
@@ -121,6 +126,7 @@ EXPAS-ARMAP-NEXT: func1 in test.dll
121126
EXPAS-ARMAP-NEXT: func2 in test.dll
122127
EXPAS-ARMAP-NEXT: func3 in test.dll
123128
EXPAS-ARMAP-NEXT: func4 in test.dll
129+
EXPAS-ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
124130

125131
EXPAS-READOBJ: File: test.dll
126132
EXPAS-READOBJ-NEXT: Format: COFF-import-file-ARM64EC

0 commit comments

Comments
 (0)