[lld] r334548 - [COFF] Fix crash when emitting symbol tables with GC
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 12 14:19:34 PDT 2018
Author: smeenai
Date: Tue Jun 12 14:19:33 2018
New Revision: 334548
URL: http://llvm.org/viewvc/llvm-project?rev=334548&view=rev
Log:
[COFF] Fix crash when emitting symbol tables with GC
When running with linker GC (`-opt:ref`), defined imported symbols that
are referenced but then dropped by GC end up with their `Location`
member being nullptr, which means `getChunk()` returns nullptr for them
and attempting to call `getChunk()->getOutputSection()` causes a crash
from the nullptr dereference. Check for `getChunk()` being nullptr and
bail out early to avoid the crash.
Differential Revision: https://reviews.llvm.org/D48092
Added:
lld/trunk/test/COFF/symtab-gc.s
Modified:
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=334548&r1=334547&r2=334548&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Tue Jun 12 14:19:33 2018
@@ -614,7 +614,10 @@ Optional<coff_symbol16> Writer::createSy
default: {
// Don't write symbols that won't be written to the output to the symbol
// table.
- OutputSection *OS = Def->getChunk()->getOutputSection();
+ Chunk *C = Def->getChunk();
+ if (!C)
+ return None;
+ OutputSection *OS = C->getOutputSection();
if (!OS)
return None;
Added: lld/trunk/test/COFF/symtab-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/symtab-gc.s?rev=334548&view=auto
==============================================================================
--- lld/trunk/test/COFF/symtab-gc.s (added)
+++ lld/trunk/test/COFF/symtab-gc.s Tue Jun 12 14:19:33 2018
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %tobject.obj %S/Inputs/object.s
+# RUN: lld-link -dll -entry:f -out:%t.dll -implib:%t.lib %tobject.obj
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %tmain.obj %s
+# RUN: lld-link -entry:main -out:%t.exe -opt:ref -debug:dwarf %tmain.obj %t.lib
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
+
+# CHECK-NOT: Symbol: f
+
+ .def main;
+ .scl 2;
+ .type 32;
+ .endef
+ .section .text,"xr",one_only,main
+ .globl main
+main:
+ retq
+
+ .def stripped;
+ .scl 3;
+ .type 32;
+ .endef
+ .section .text,"xr",one_only,stripped
+stripped:
+ callq __imp_f
+ retq
More information about the llvm-commits
mailing list