Skip to content

Commit 750de32

Browse files
authored
[COFF] Rename the COFFShortExport::AliasTarget field. NFC. (#89039)
It turns out that the previous name is vaguely misleading. When operating on a def file like "symbolname == dllname", that is supposed to make an import library entry, that when the symbol "symbolname" links against this, it imports the DLL symbol "dllname" from the referenced DLL. This doesn't need to involve any alias, and it doesn't need to imply that "dllname" is available on its own as a separate symbol in the import library at all. GNU dlltool implements import libraries in the form of "long import library", where each member is a regular object file with section chunks that compose the relevant .idata section pieces. There, this kind of import renaming does not involve any form of aliases, but the right .idata section just gets a different string than the symbol name.
1 parent 3e64f8a commit 750de32

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

lld/COFF/Config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct Export {
5555
StringRef name; // N in /export:N or /export:E=N
5656
StringRef extName; // E in /export:E=N
5757
StringRef exportAs; // E in /export:N,EXPORTAS,E
58-
StringRef aliasTarget; // GNU specific: N in "alias == N"
58+
StringRef importName; // GNU specific: N in "othername == N"
5959
Symbol *sym = nullptr;
6060
uint16_t ordinal = 0;
6161
bool noname = false;
@@ -75,7 +75,7 @@ struct Export {
7575

7676
bool operator==(const Export &e) const {
7777
return (name == e.name && extName == e.extName && exportAs == e.exportAs &&
78-
aliasTarget == e.aliasTarget && ordinal == e.ordinal &&
78+
importName == e.importName && ordinal == e.ordinal &&
7979
noname == e.noname && data == e.data && isPrivate == e.isPrivate);
8080
}
8181
};

lld/COFF/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
934934
e2.SymbolName = std::string(e1.symbolName);
935935
e2.ExtName = std::string(e1.extName);
936936
e2.ExportAs = std::string(e1.exportAs);
937-
e2.AliasTarget = std::string(e1.aliasTarget);
937+
e2.ImportName = std::string(e1.importName);
938938
e2.Ordinal = e1.ordinal;
939939
e2.Noname = e1.noname;
940940
e2.Data = e1.data;
@@ -1034,7 +1034,7 @@ void LinkerDriver::parseModuleDefs(StringRef path) {
10341034
e2.extName = saver().save(e1.ExtName);
10351035
}
10361036
e2.exportAs = saver().save(e1.ExportAs);
1037-
e2.aliasTarget = saver().save(e1.AliasTarget);
1037+
e2.importName = saver().save(e1.ImportName);
10381038
e2.ordinal = e1.Ordinal;
10391039
e2.noname = e1.Noname;
10401040
e2.data = e1.Data;

llvm/include/llvm/Object/COFFImportFile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ struct COFFShortExport {
9898
/// "/export:foo=bar", this could be "_bar@8" if bar is stdcall.
9999
std::string SymbolName;
100100

101-
/// Creates a weak alias. This is the name of the weak aliasee. In a .def
101+
/// Creates an import library entry that imports from a DLL export with a
102+
/// different name. This is the name of the DLL export that should be
103+
/// referenced when linking against this import library entry. In a .def
102104
/// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
103-
std::string AliasTarget;
105+
std::string ImportName;
104106

105107
/// Specifies EXPORTAS name. In a .def file, this is "bar" in
106108
/// "EXPORTS\nfoo EXPORTAS bar".

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,9 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
690690
Name.swap(*ReplacedName);
691691
}
692692

693-
if (!E.AliasTarget.empty() && Name != E.AliasTarget) {
694-
Members.push_back(OF.createWeakExternal(E.AliasTarget, Name, false, M));
695-
Members.push_back(OF.createWeakExternal(E.AliasTarget, Name, true, M));
693+
if (!E.ImportName.empty() && Name != E.ImportName) {
694+
Members.push_back(OF.createWeakExternal(E.ImportName, Name, false, M));
695+
Members.push_back(OF.createWeakExternal(E.ImportName, Name, true, M));
696696
continue;
697697
}
698698

llvm/lib/Object/COFFModuleDefinition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ class Parser {
281281
}
282282
if (Tok.K == EqualEqual) {
283283
read();
284-
E.AliasTarget = std::string(Tok.Value);
285-
if (AddUnderscores && !isDecorated(E.AliasTarget, MingwDef))
286-
E.AliasTarget = std::string("_").append(E.AliasTarget);
284+
E.ImportName = std::string(Tok.Value);
285+
if (AddUnderscores && !isDecorated(E.ImportName, MingwDef))
286+
E.ImportName = std::string("_").append(E.ImportName);
287287
continue;
288288
}
289289
// EXPORTAS must be at the end of export definition

llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
227227

228228
if (Machine == IMAGE_FILE_MACHINE_I386 && Args.hasArg(OPT_k)) {
229229
for (COFFShortExport &E : Exports) {
230-
if (!E.AliasTarget.empty() || (!E.Name.empty() && E.Name[0] == '?'))
230+
if (!E.ImportName.empty() || (!E.Name.empty() && E.Name[0] == '?'))
231231
continue;
232232
E.SymbolName = E.Name;
233233
// Trim off the trailing decoration. Symbols will always have a

0 commit comments

Comments
 (0)