From 2adccee13f1df8282295a0382117543c04708c06 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 19 Oct 2016 14:50:26 +0000 Subject: [PATCH] Don't gc non-alloca non-string pieces. We were already doing it for strings. This matches the behavior of bfd and gold. llvm-svn: 284598 --- lld/ELF/InputSection.cpp | 3 ++- lld/test/ELF/debug-gc.s | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 296c3a67c6e1..76795a24ac62 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -615,8 +615,9 @@ MergeInputSection::splitNonStrings(ArrayRef Data, std::vector V; size_t Size = Data.size(); assert((Size % EntSize) == 0); + bool IsAlloca = this->getSectionHdr()->sh_flags & SHF_ALLOC; for (unsigned I = 0, N = Size; I != N; I += EntSize) - V.emplace_back(I, Data.slice(I, EntSize)); + V.emplace_back(I, Data.slice(I, EntSize), !IsAlloca); return V; } diff --git a/lld/test/ELF/debug-gc.s b/lld/test/ELF/debug-gc.s index 5254220f5cb0..8bcfde16a7b7 100644 --- a/lld/test/ELF/debug-gc.s +++ b/lld/test/ELF/debug-gc.s @@ -5,6 +5,8 @@ # CHECK: Contents of section .debug_str: # CHECK-NEXT: 0000 41414100 42424200 43434300 AAA.BBB.CCC. +# CHECK: Contents of section .foo: +# CHECK-NEXT: 0000 2a000000 # CHECK: Contents of section .debug_info: # CHECK-NEXT: 0000 00000000 04000000 @@ -19,6 +21,10 @@ _start: .Linfo_string2: .asciz "CCC" +.section .foo,"M",@progbits,4 +.p2align 2 + .long 42 + .section .debug_info,"",@progbits .long .Linfo_string0 .long .Linfo_string1