diff options
| -rw-r--r-- | lld/COFF/SymbolTable.cpp | 10 | ||||
| -rw-r--r-- | lld/COFF/Symbols.h | 8 | ||||
| -rw-r--r-- | lld/test/COFF/duplicate-absolute-same.s | 14 | ||||
| -rw-r--r-- | lld/test/COFF/duplicate-absolute.s | 2 |
4 files changed, 31 insertions, 3 deletions
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index e6f9d70568f..b6e180ff9d0 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -591,7 +591,10 @@ Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) { s->isUsedInRegularObj = true; if (wasInserted || isa<Undefined>(s) || s->isLazy()) replaceSymbol<DefinedAbsolute>(s, n, sym); - else if (!isa<DefinedCOFF>(s)) + else if (auto *da = dyn_cast<DefinedAbsolute>(s)) { + if (!da->isEqual(sym)) + reportDuplicate(s, nullptr); + } else if (!isa<DefinedCOFF>(s)) reportDuplicate(s, nullptr); return s; } @@ -603,7 +606,10 @@ Symbol *SymbolTable::addAbsolute(StringRef n, uint64_t va) { s->isUsedInRegularObj = true; if (wasInserted || isa<Undefined>(s) || s->isLazy()) replaceSymbol<DefinedAbsolute>(s, n, va); - else if (!isa<DefinedCOFF>(s)) + else if (auto *da = dyn_cast<DefinedAbsolute>(s)) { + if (!da->isEqual(va)) + reportDuplicate(s, nullptr); + } else if (!isa<DefinedCOFF>(s)) reportDuplicate(s, nullptr); return s; } diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index fd79bd5065b..2d74dea63af 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -229,6 +229,14 @@ public: uint64_t getRVA() { return va - config->imageBase; } void setVA(uint64_t v) { va = v; } + bool isEqual(COFFSymbolRef s) const { + return va == s.getValue(); + } + + bool isEqual(uint64_t otherVa) const { + return va == otherVa; + } + // Section index relocations against absolute symbols resolve to // this 16 bit number, and it is the largest valid section index // plus one. This variable keeps it. diff --git a/lld/test/COFF/duplicate-absolute-same.s b/lld/test/COFF/duplicate-absolute-same.s new file mode 100644 index 00000000000..e8c807c1814 --- /dev/null +++ b/lld/test/COFF/duplicate-absolute-same.s @@ -0,0 +1,14 @@ +// REQUIRES: x86 +// RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.obj %s +// RUN: echo -e ".globl myabsolute\nmyabsolute = 0" > %t.dupl.s +// RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.dupl.obj %t.dupl.s +// RUN: lld-link /out:%t.exe %t.obj %t.dupl.obj -subsystem:console -entry:entry 2>&1 | FileCheck --allow-empty %s + +// CHECK-NOT: error: duplicate symbol: myabsolute + +.globl myabsolute +myabsolute = 0 + +.globl entry +entry: + ret diff --git a/lld/test/COFF/duplicate-absolute.s b/lld/test/COFF/duplicate-absolute.s index 0d7e0d38d8b..54d628506fa 100644 --- a/lld/test/COFF/duplicate-absolute.s +++ b/lld/test/COFF/duplicate-absolute.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.obj %s -// RUN: echo -e ".globl myabsolute\nmyabsolute = 0" > %t.dupl.s +// RUN: echo -e ".globl myabsolute\nmyabsolute = 1" > %t.dupl.s // RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.dupl.obj %t.dupl.s // RUN: not lld-link /out:%t.exe %t.obj %t.dupl.obj 2>&1 | FileCheck %s |

