Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -606,13 +606,14 @@ if (isa(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(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 @@ 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; } } Index: test/COFF/gfids-gc.s =================================================================== --- test/COFF/gfids-gc.s +++ test/COFF/gfids-gc.s @@ -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 Index: test/COFF/safeseh.s =================================================================== --- test/COFF/safeseh.s +++ test/COFF/safeseh.s @@ -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 [