[lld] r333450 - [COFF] Simplify symbol table output section computation
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Tue May 29 12:07:48 PDT 2018
Author: smeenai
Date: Tue May 29 12:07:47 2018
New Revision: 333450
URL: http://llvm.org/viewvc/llvm-project?rev=333450&view=rev
Log:
[COFF] Simplify symbol table output section computation
Rather than using a loop to compare symbol RVAs to the starting RVAs of
sections to determine which section a symbol belongs to, just get the
output section of a symbol directly via its chunk, and bail if the
symbol doesn't have an output section, which avoids having to hardcode
logic for handling dead symbols, CodeView symbols, etc. This was
suggested by Reid Kleckner; thank you.
This also fixes writing out symbol tables in the presence of RVA table
input sections (e.g. .sxdata and .gfids). Such sections aren't written
to the output file directly, so their RVA is 0, and the loop would thus
fail to find an output section for them, resulting in a segfault. Extend
some existing tests to cover this case.
Fixes PR37584.
Differential Revision: https://reviews.llvm.org/D47391
Modified:
lld/trunk/COFF/Writer.cpp
lld/trunk/test/COFF/gfids-gc.s
lld/trunk/test/COFF/safeseh.s
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=333450&r1=333449&r2=333450&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Tue May 29 12:07:47 2018
@@ -606,13 +606,14 @@ Optional<coff_symbol16> Writer::createSy
if (isa<DefinedSynthetic>(Def))
return None;
- // Don't write dead symbols or symbols in codeview sections to the symbol
+ // Don't write symbols that won't be written to the output to the symbol
// table.
- if (!Def->isLive())
- return None;
- if (auto *D = dyn_cast<DefinedRegular>(Def))
- if (D->getChunk()->isCodeView())
+ OutputSection *OS = nullptr;
+ if (Chunk *C = Def->getChunk()) {
+ OS = C->getOutputSection();
+ if (!OS)
return None;
+ }
coff_symbol16 Sym;
StringRef Name = Def->getName();
@@ -640,15 +641,9 @@ Optional<coff_symbol16> Writer::createSy
Sym.SectionNumber = IMAGE_SYM_ABSOLUTE;
break;
default: {
- uint64_t RVA = Def->getRVA();
- OutputSection *Sec = nullptr;
- for (OutputSection *S : OutputSections) {
- if (S->getRVA() > RVA)
- break;
- Sec = S;
- }
- Sym.Value = RVA - Sec->getRVA();
- Sym.SectionNumber = Sec->SectionIndex;
+ assert(OS && "Writing dead symbol to symbol table");
+ Sym.Value = Def->getRVA() - OS->getRVA();
+ Sym.SectionNumber = OS->SectionIndex;
break;
}
}
Modified: lld/trunk/test/COFF/gfids-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/gfids-gc.s?rev=333450&r1=333449&r2=333450&view=diff
==============================================================================
--- lld/trunk/test/COFF/gfids-gc.s (original)
+++ lld/trunk/test/COFF/gfids-gc.s Tue May 29 12:07:47 2018
@@ -1,6 +1,8 @@
# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
# RUN: lld-link %t.obj -guard:nolongjmp -out:%t.exe -opt:noref -entry:main
# RUN: llvm-readobj -file-headers -coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
+# RUN: lld-link %t.obj -guard:nolongjmp -out:%t.exe -opt:noref -entry:main -debug:dwarf
+# RUN: llvm-readobj -file-headers -coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
# RUN: lld-link %t.obj -guard:nolongjmp -out:%t.exe -opt:ref -entry:main
# RUN: llvm-readobj -file-headers -coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-GC
Modified: lld/trunk/test/COFF/safeseh.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/safeseh.s?rev=333450&r1=333449&r2=333450&view=diff
==============================================================================
--- lld/trunk/test/COFF/safeseh.s (original)
+++ lld/trunk/test/COFF/safeseh.s Tue May 29 12:07:47 2018
@@ -1,6 +1,8 @@
# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t.obj
# RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:noref -entry:main
# RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
+# RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:noref -entry:main -debug:dwarf
+# RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
# RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:ref -entry:main
# RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-GC
@@ -13,7 +15,7 @@
# CHECK-NOGC: Type: HIGHLOW
# CHECK-NOGC: LoadConfig [
# CHECK-NOGC: Size: 0x48
-# CHECK-NOGC: SEHandlerTable: 0x402048
+# CHECK-NOGC: SEHandlerTable: 0x
# CHECK-NOGC: SEHandlerCount: 1
# CHECK-NOGC: ]
# CHECK-NOGC: SEHTable [
More information about the llvm-commits
mailing list