Skip to content

Commit 6e8d3ce

Browse files
committed
Copy import descriptors to the EC Map
1 parent fe8cf2f commit 6e8d3ce

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

llvm/include/llvm/Object/COFFImportFile.h

+6
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

+11
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

+4-6
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-dlltool/arm64ec.test

+6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
1212
ARMAP-EMPTY:
1313
ARMAP-NEXT: Archive EC map
1414
ARMAP-NEXT: #func in test.dll
15+
ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
16+
ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
1517
ARMAP-NEXT: __imp_aux_func in test.dll
1618
ARMAP-NEXT: __imp_func in test.dll
1719
ARMAP-NEXT: func in test.dll
20+
ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
1821

1922
RUN: llvm-dlltool -m arm64ec -d test.def -N test2.def -l test2.lib
2023
RUN: llvm-nm --print-armap test2.lib | FileCheck --check-prefix=ARMAP2 %s
@@ -28,9 +31,12 @@ ARMAP2-NEXT: test_NULL_THUNK_DATA in test.dll
2831
ARMAP2-EMPTY:
2932
ARMAP2-NEXT: Archive EC map
3033
ARMAP2-NEXT: #func in test.dll
34+
ARMAP2-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
35+
ARMAP2-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
3136
ARMAP2-NEXT: __imp_aux_func in test.dll
3237
ARMAP2-NEXT: __imp_func in test.dll
3338
ARMAP2-NEXT: func in test.dll
39+
ARMAP2-NEXT: test_NULL_THUNK_DATA in test.dll
3440

3541
RUN: llvm-dlltool -m arm64ec -d test.def --input-native-def test2.def -l test3.lib
3642
RUN: llvm-nm --print-armap test3.lib | FileCheck --check-prefix=ARMAP2 %s

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

+12
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

@@ -122,6 +125,8 @@ ARMAPX-NEXT: #funcexp in test.dll
122125
ARMAPX-NEXT: #mangledfunc in test.dll
123126
ARMAPX-NEXT: ?test_cpp_func@@$$hYAHPEAX@Z in test.dll
124127
ARMAPX-NEXT: ?test_cpp_func@@YAHPEAX@Z in test.dll
128+
ARMAPX-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
129+
ARMAPX-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
125130
ARMAPX-NEXT: __imp_?test_cpp_func@@YAHPEAX@Z in test.dll
126131
ARMAPX-NEXT: __imp_aux_?test_cpp_func@@YAHPEAX@Z in test.dll
127132
ARMAPX-NEXT: __imp_aux_expname in test.dll
@@ -134,6 +139,7 @@ ARMAPX-NEXT: __imp_mangledfunc in test.dll
134139
ARMAPX-NEXT: expname in test.dll
135140
ARMAPX-NEXT: funcexp in test.dll
136141
ARMAPX-NEXT: mangledfunc in test.dll
142+
ARMAPX-NEXT: test_NULL_THUNK_DATA in test.dll
137143

138144
RUN: llvm-readobj testx.lib | FileCheck -check-prefix=READOBJX %s
139145

@@ -255,6 +261,8 @@ ARMAPX2-NEXT: #funcexp in test2.dll
255261
ARMAPX2-NEXT: #mangledfunc in test2.dll
256262
ARMAPX2-NEXT: ?test_cpp_func@@$$hYAHPEAX@Z in test2.dll
257263
ARMAPX2-NEXT: ?test_cpp_func@@YAHPEAX@Z in test2.dll
264+
ARMAPX2-NEXT: __IMPORT_DESCRIPTOR_test2 in test2.dll
265+
ARMAPX2-NEXT: __NULL_IMPORT_DESCRIPTOR in test2.dll
258266
ARMAPX2-NEXT: __imp_?test_cpp_func@@YAHPEAX@Z in test2.dll
259267
ARMAPX2-NEXT: __imp_aux_?test_cpp_func@@YAHPEAX@Z in test2.dll
260268
ARMAPX2-NEXT: __imp_aux_expname in test2.dll
@@ -267,6 +275,7 @@ ARMAPX2-NEXT: __imp_mangledfunc in test2.dll
267275
ARMAPX2-NEXT: expname in test2.dll
268276
ARMAPX2-NEXT: funcexp in test2.dll
269277
ARMAPX2-NEXT: mangledfunc in test2.dll
278+
ARMAPX2-NEXT: test2_NULL_THUNK_DATA in test2.dll
270279

271280
ARMAPX2: test2.dll:
272281
ARMAPX2: 00000000 T #funcexp
@@ -309,6 +318,8 @@ EXPAS-ARMAP-NEXT: #func1 in test.dll
309318
EXPAS-ARMAP-NEXT: #func2 in test.dll
310319
EXPAS-ARMAP-NEXT: #func3 in test.dll
311320
EXPAS-ARMAP-NEXT: #func4 in test.dll
321+
EXPAS-ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
322+
EXPAS-ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
312323
EXPAS-ARMAP-NEXT: __imp_aux_func1 in test.dll
313324
EXPAS-ARMAP-NEXT: __imp_aux_func2 in test.dll
314325
EXPAS-ARMAP-NEXT: __imp_aux_func3 in test.dll
@@ -323,6 +334,7 @@ EXPAS-ARMAP-NEXT: func1 in test.dll
323334
EXPAS-ARMAP-NEXT: func2 in test.dll
324335
EXPAS-ARMAP-NEXT: func3 in test.dll
325336
EXPAS-ARMAP-NEXT: func4 in test.dll
337+
EXPAS-ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll
326338

327339
EXPAS-READOBJ: File: test.dll
328340
EXPAS-READOBJ-NEXT: Format: COFF-import-file-ARM64EC

0 commit comments

Comments
 (0)