Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -441,6 +441,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(Args); @@ -1617,11 +1622,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); Index: lld/trunk/test/ELF/undef-broken-debug.test =================================================================== --- lld/trunk/test/ELF/undef-broken-debug.test +++ lld/trunk/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