[PATCH] D61712: [ELF] Initialize Target before it may be referenced by findAux when reporting "duplicate symbol" error
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 18:28:24 PDT 2019
MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, atanasyan, arichardson, aprantl, sdardis, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
for (InputFile *F : Files)
Symtab->addFile<ELFT>(F); // if there is a duplicate symbol error
...
Target = getTarget();
When parsing .debug_info in the object file (for better diagnostics),
DWARF.cpp findAux may dereference the null pointer Target
auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
if (!DR) { /// Some asan object files contain R_X86_64_NONE
RelType Type = Rel.getType(Config->IsMips64EL);
if (Type != Target->NoneRel) /// Target is null
Move the assignment of Target to an earlier place to fix this.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D61712
Files:
ELF/Driver.cpp
test/ELF/undef-broken-debug.test
Index: test/ELF/undef-broken-debug.test
===================================================================
--- test/ELF/undef-broken-debug.test
+++ test/ELF/undef-broken-debug.test
@@ -8,6 +8,10 @@
# CHECK: error: {{.*}}.o: relocation R_X86_64_64 at 0x29 has unsupported target
# CHECK: error: undefined symbol: bar
+# We used to dereference null Target in DWARF.cpp:findAux while reporting a duplicate symbol error,
+# because Target wasn't initialized yet.
+# RUN: not ld.lld %t.o %t.o -o /dev/null
+
--- !ELF
FileHeader:
Class: ELFCLASS64
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -440,6 +440,11 @@
if (errorCount())
return;
+ // The Target instance handles target-specific stuff, such as applying
+ // relocations or writing a PLT section. It also contains target-dependent
+ // values such as a default image base address.
+ Target = getTarget();
+
switch (Config->EKind) {
case ELF32LEKind:
link<ELF32LE>(Args);
@@ -1616,11 +1621,6 @@
if (Config->Strip != StripPolicy::None)
llvm::erase_if(InputSections, [](InputSectionBase *S) { return S->Debug; });
- // The Target instance handles target-specific stuff, such as applying
- // relocations or writing a PLT section. It also contains target-dependent
- // values such as a default image base address.
- Target = getTarget();
-
Config->EFlags = Target->calcEFlags();
Config->MaxPageSize = getMaxPageSize(Args);
Config->ImageBase = getImageBase(Args);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61712.198753.patch
Type: text/x-patch
Size: 1564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190509/c85b1f85/attachment-0001.bin>
More information about the llvm-commits
mailing list