Skip to content

Commit 7c26407

Browse files
authored
[LLD][COFF] Clarify EC vs. native symbols in diagnostics on ARM64X (#130857)
On ARM64X, symbol names alone are ambiguous as they may refer to either a native or an EC symbol. Append '(EC symbol)' or '(native symbol)' in diagnostic messages to distinguish them.
1 parent 8560da2 commit 7c26407

File tree

10 files changed

+44
-33
lines changed

10 files changed

+44
-33
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ void ObjFile::handleComdatSelection(
705705
// seems better though.
706706
// (This behavior matches ModuleLinker::getComdatResult().)
707707
if (selection != leaderSelection) {
708-
Log(ctx) << "conflicting comdat type for " << leader << ": "
709-
<< (int)leaderSelection << " in " << leader->getFile() << " and "
710-
<< (int)selection << " in " << this;
708+
Log(ctx) << "conflicting comdat type for " << symtab.printSymbol(leader)
709+
<< ": " << (int)leaderSelection << " in " << leader->getFile()
710+
<< " and " << (int)selection << " in " << this;
711711
symtab.reportDuplicate(leader, this);
712712
return;
713713
}

lld/COFF/SymbolTable.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ struct UndefinedDiag {
214214
std::vector<File> files;
215215
};
216216

217-
static void reportUndefinedSymbol(COFFLinkerContext &ctx,
218-
const UndefinedDiag &undefDiag) {
217+
void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
219218
auto diag = errorOrWarn(ctx);
220-
diag << "undefined symbol: " << undefDiag.sym;
219+
diag << "undefined symbol: " << printSymbol(undefDiag.sym);
221220

222221
const size_t maxUndefReferences = 3;
223222
size_t numDisplayedRefs = 0, numRefs = 0;
@@ -363,12 +362,12 @@ void SymbolTable::reportProblemSymbols(
363362

364363
for (Symbol *b : ctx.config.gcroot) {
365364
if (undefs.count(b))
366-
errorOrWarn(ctx) << "<root>: undefined symbol: " << b;
365+
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
367366
if (localImports)
368367
if (Symbol *imp = localImports->lookup(b))
369-
Warn(ctx) << "<root>: locally defined symbol imported: " << imp
370-
<< " (defined in " << toString(imp->getFile())
371-
<< ") [LNK4217]";
368+
Warn(ctx) << "<root>: locally defined symbol imported: "
369+
<< printSymbol(imp) << " (defined in "
370+
<< toString(imp->getFile()) << ") [LNK4217]";
372371
}
373372

374373
std::vector<UndefinedDiag> undefDiags;
@@ -389,7 +388,8 @@ void SymbolTable::reportProblemSymbols(
389388
}
390389
if (localImports)
391390
if (Symbol *imp = localImports->lookup(sym))
392-
Warn(ctx) << file << ": locally defined symbol imported: " << imp
391+
Warn(ctx) << file
392+
<< ": locally defined symbol imported: " << printSymbol(imp)
393393
<< " (defined in " << imp->getFile() << ") [LNK4217]";
394394
}
395395
};
@@ -402,7 +402,7 @@ void SymbolTable::reportProblemSymbols(
402402
processFile(file, file->getSymbols());
403403

404404
for (const UndefinedDiag &undefDiag : undefDiags)
405-
reportUndefinedSymbol(ctx, undefDiag);
405+
reportUndefinedSymbol(undefDiag);
406406
}
407407

408408
void SymbolTable::reportUnresolvable() {
@@ -822,7 +822,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
822822
uint32_t newSectionOffset) {
823823
COFFSyncStream diag(ctx, ctx.config.forceMultiple ? DiagLevel::Warn
824824
: DiagLevel::Err);
825-
diag << "duplicate symbol: " << existing;
825+
diag << "duplicate symbol: " << printSymbol(existing);
826826

827827
DefinedRegular *d = dyn_cast<DefinedRegular>(existing);
828828
if (d && isa<ObjFile>(d->getFile())) {
@@ -1350,6 +1350,13 @@ Symbol *SymbolTable::addUndefined(StringRef name) {
13501350
return addUndefined(name, nullptr, false);
13511351
}
13521352

1353+
std::string SymbolTable::printSymbol(Symbol *sym) const {
1354+
std::string name = maybeDemangleSymbol(ctx, sym->getName());
1355+
if (ctx.hybridSymtab)
1356+
return name + (isEC() ? " (EC symbol)" : " (native symbol)");
1357+
return name;
1358+
}
1359+
13531360
void SymbolTable::compileBitcodeFiles() {
13541361
if (bitcodeFileInstances.empty())
13551362
return;

lld/COFF/SymbolTable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct WrappedSymbol {
4141
Symbol *wrap;
4242
};
4343

44+
struct UndefinedDiag;
45+
4446
// SymbolTable is a bucket of all known symbols, including defined,
4547
// undefined, or lazy symbols (the last one is symbols in archive
4648
// files whose archive members are not yet loaded).
@@ -195,6 +197,8 @@ class SymbolTable {
195197
uint32_t loadConfigSize = 0;
196198
void initializeLoadConfig();
197199

200+
std::string printSymbol(Symbol *sym) const;
201+
198202
private:
199203
/// Given a name without "__imp_" prefix, returns a defined symbol
200204
/// with the "__imp_" prefix, if it exists.
@@ -216,6 +220,7 @@ class SymbolTable {
216220
reportProblemSymbols(const llvm::SmallPtrSetImpl<Symbol *> &undefs,
217221
const llvm::DenseMap<Symbol *, Symbol *> *localImports,
218222
bool needBitcodeFiles);
223+
void reportUndefinedSymbol(const UndefinedDiag &undefDiag);
219224
};
220225

221226
std::vector<std::string> getSymbolLocations(ObjFile *file, uint32_t symIndex);

lld/COFF/Symbols.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ coff::operator<<(const COFFSyncStream &s,
6060
return s;
6161
}
6262

63-
const COFFSyncStream &coff::operator<<(const COFFSyncStream &s, Symbol *sym) {
64-
return s << maybeDemangleSymbol(s.ctx, sym->getName());
65-
}
66-
6763
namespace coff {
6864

6965
void Symbol::computeName() {

lld/COFF/Symbols.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class SymbolTable;
3838

3939
const COFFSyncStream &operator<<(const COFFSyncStream &,
4040
const llvm::object::Archive::Symbol *);
41-
const COFFSyncStream &operator<<(const COFFSyncStream &, Symbol *);
4241

4342
// The base class for real symbol classes.
4443
class Symbol {

lld/COFF/Writer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,12 +1282,13 @@ void Writer::createImportTables() {
12821282
ctx.config.dllOrder[dll] = ctx.config.dllOrder.size();
12831283

12841284
if (file->impSym && !isa<DefinedImportData>(file->impSym))
1285-
Fatal(ctx) << file->impSym << " was replaced";
1285+
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
12861286
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
12871287
if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
12881288
if (!file->thunkSym)
12891289
Fatal(ctx) << "cannot delay-load " << toString(file)
1290-
<< " due to import of data: " << impSym;
1290+
<< " due to import of data: "
1291+
<< file->symtab.printSymbol(impSym);
12911292
delayIdata.add(impSym);
12921293
} else {
12931294
idata.add(impSym);
@@ -1306,15 +1307,17 @@ void Writer::appendImportThunks() {
13061307

13071308
if (file->thunkSym) {
13081309
if (!isa<DefinedImportThunk>(file->thunkSym))
1309-
Fatal(ctx) << file->thunkSym << " was replaced";
1310+
Fatal(ctx) << file->symtab.printSymbol(file->thunkSym)
1311+
<< " was replaced";
13101312
auto *chunk = cast<DefinedImportThunk>(file->thunkSym)->getChunk();
13111313
if (chunk->live)
13121314
textSec->addChunk(chunk);
13131315
}
13141316

13151317
if (file->auxThunkSym) {
13161318
if (!isa<DefinedImportThunk>(file->auxThunkSym))
1317-
Fatal(ctx) << file->auxThunkSym << " was replaced";
1319+
Fatal(ctx) << file->symtab.printSymbol(file->auxThunkSym)
1320+
<< " was replaced";
13181321
auto *chunk = cast<DefinedImportThunk>(file->auxThunkSym)->getChunk();
13191322
if (chunk->live)
13201323
textSec->addChunk(chunk);

lld/test/COFF/arm64x-altnames.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// RUN: 2>&1 | FileCheck --check-prefix=ERR-NATIVE %s
1313

1414
// ERR-NATIVE-NOT: test-arm64ec.obj
15-
// ERR-NATIVE: lld-link: error: undefined symbol: sym
15+
// ERR-NATIVE: lld-link: error: undefined symbol: sym (native symbol)
1616
// ERR-NATIVE-NEXT: >>> referenced by test-arm64.obj:(.test)
1717
// ERR-NATIVE-NOT: test-arm64ec.obj
1818

@@ -25,7 +25,7 @@
2525
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
2626

2727
// ERR-EC-NOT: test-arm64.obj
28-
// ERR-EC: lld-link: error: undefined symbol: sym
28+
// ERR-EC: lld-link: error: undefined symbol: sym (EC symbol)
2929
// ERR-EC-NEXT: >>> referenced by test-arm64ec.obj:(.test)
3030
// ERR-EC-NOT: test-arm64.obj
3131

lld/test/COFF/arm64x-incl.s

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
// Check that including a missing symbol results in an error.
4141

4242
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj -include:sym sym-aarch64.obj \
43-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
44-
// ERR: lld-link: error: <root>: undefined symbol: sym
43+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
44+
// ERR-EC: lld-link: error: <root>: undefined symbol: sym (EC symbol)
4545

4646
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj drectve-arm64ec.obj sym-aarch64.obj \
47-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
47+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
4848

4949
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj drectve-aarch64.obj sym-arm64ec.obj \
50-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
50+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-NATIVE %s
51+
// ERR-NATIVE: lld-link: error: <root>: undefined symbol: sym (native symbol)
5152

5253
#--- sym-aarch64.s
5354
.section ".test","dr"

lld/test/COFF/arm64x-symtab.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
// RUN: not lld-link -machine:arm64x -dll -noentry -out:err1.dll symref-aarch64.obj sym-arm64ec.obj \
2020
// RUN: 2>&1 | FileCheck --check-prefix=UNDEF %s
21-
// UNDEF: lld-link: error: undefined symbol: sym
21+
// UNDEF: lld-link: error: undefined symbol: sym (native symbol)
2222
// UNDEF-NEXT: >>> referenced by symref-aarch64.obj:(.data)
2323

2424
// Check that EC object files can't reference native symbols.
2525

2626
// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-arm64ec.obj sym-aarch64.obj \
2727
// RUN: 2>&1 | FileCheck --check-prefix=UNDEFEC %s
28-
// UNDEFEC: lld-link: error: undefined symbol: sym
28+
// UNDEFEC: lld-link: error: undefined symbol: sym (EC symbol)
2929
// UNDEFEC-NEXT: >>> referenced by symref-arm64ec.obj:(.data)
3030

3131
// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-x86_64.obj sym-aarch64.obj \
3232
// RUN: 2>&1 | FileCheck --check-prefix=UNDEFX86 %s
33-
// UNDEFX86: lld-link: error: undefined symbol: sym
33+
// UNDEFX86: lld-link: error: undefined symbol: sym (EC symbol)
3434
// UNDEFX86-NEXT: >>> referenced by symref-x86_64.obj:(.data)
3535

3636
// RUN: not lld-link -machine:arm64x -dll -noentry -out:err2.dll symref-aarch64.obj sym-x86_64.obj \

lld/test/COFF/locally-imported-arm64x.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.arm64ec.obj
55

66
// RUN: lld-link -machine:arm64x -dll -noentry %t.arm64.obj %t.arm64ec.obj -out:%t.dll 2>&1 | FileCheck --check-prefix=WARN %s
7-
// WARN: lld-link: warning: {{.*}}.arm64.obj: locally defined symbol imported: func
8-
// WARN-NEXT: lld-link: warning: {{.*}}.arm64ec.obj: locally defined symbol imported: func
7+
// WARN: lld-link: warning: {{.*}}.arm64.obj: locally defined symbol imported: func (native symbol)
8+
// WARN-NEXT: lld-link: warning: {{.*}}.arm64ec.obj: locally defined symbol imported: func (EC symbol)
99

1010
// RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck --check-prefix=TEST %s
1111
// TEST: 0x180005000 00300000 08300000

0 commit comments

Comments
 (0)