diff options
-rw-r--r-- | lld/ELF/Driver.cpp | 10 | ||||
-rw-r--r-- | lld/test/ELF/undef-broken-debug.test | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 6799ea9c041..27f186414d3 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -441,6 +441,11 @@ void LinkerDriver::main(ArrayRef<const char *> ArgsArr) { 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); @@ -1617,11 +1622,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { 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); diff --git a/lld/test/ELF/undef-broken-debug.test b/lld/test/ELF/undef-broken-debug.test index 444f3bf3f74..2ca8494a180 100644 --- a/lld/test/ELF/undef-broken-debug.test +++ b/lld/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 |