[PATCH] D37561: [ELF] - Don't crash when --emit-relocs is used with --gc-sections
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 02:29:09 PDT 2017
grimar updated this revision to Diff 115382.
grimar added a comment.
- Addressed review comment.
https://reviews.llvm.org/D37561
Files:
ELF/InputSection.cpp
test/ELF/emit-relocs-gc.s
Index: test/ELF/emit-relocs-gc.s
===================================================================
--- test/ELF/emit-relocs-gc.s
+++ test/ELF/emit-relocs-gc.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+## Show that we emit .rela.bar when GC is disabled.
+# RUN: ld.lld --emit-relocs %t.o -o %t
+# RUN: llvm-objdump %t -section-headers | FileCheck %s --check-prefix=NOGC
+# NOGC: .rela.bar
+
+## GC collects .bar section and we exclude .rela.bar from output.
+# RUN: ld.lld --gc-sections --emit-relocs --print-gc-sections %t.o -o %t \
+# RUN: | FileCheck --check-prefix=MSG %s
+# MSG: removing unused section from '.bar' in file
+# MSG: removing unused section from '.rela.bar' in file
+# RUN: llvm-objdump %t -section-headers | FileCheck %s --check-prefix=GC
+# GC-NOT: rela.bar
+
+.section .bar,"a"
+.quad .bar
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -83,7 +83,14 @@
: SectionBase(SectionKind, Name, Flags, Entsize, Alignment, Type, Info,
Link),
File(File), Data(Data), Repl(this) {
- Live = !Config->GcSections || !(Flags & SHF_ALLOC);
+ Live = !Config->GcSections;
+ // Non-allocatable sections are usually used for debug information,
+ // we do not run GC for them. But we should still eliminate SHT_REL[A]
+ // sections in case when their target sections were GCed.
+ // It is required for -emit-relocs.
+ if (!(Flags & SHF_ALLOC))
+ Live |= Type != SHT_REL && Type != SHT_RELA;
+
Assigned = false;
NumRelocations = 0;
AreRelocsRela = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37561.115382.patch
Type: text/x-patch
Size: 1675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170915/5aecdb40/attachment.bin>
More information about the llvm-commits
mailing list