[llvm] r206653 - Update the fragments of symbols in compressed sections.
David Blaikie
dblaikie at gmail.com
Fri Apr 18 14:24:12 PDT 2014
Author: dblaikie
Date: Fri Apr 18 16:24:12 2014
New Revision: 206653
URL: http://llvm.org/viewvc/llvm-project?rev=206653&view=rev
Log:
Update the fragments of symbols in compressed sections.
While unnamed relocations are already cached in side tables in
ELFObjectWriter::RecordRelocation, symbols still need their fragments
updated to refer to the newly compressed fragment (even if that fragment
isn't big enough to fit the offset). Even though we only create
temporary symbols in debug info sections this comes up in 32 bit builds
where even temporary symbols in mergeable sections (such as debug_str)
have to be emitted as named symbols.
I tried a few other ways to do this but they all didn't work for various
reasons:
1) Canonicalize the MCSymbolData in RecordRelocation, nulling out the
Fragment (so it didn't have to be updated by CompressDebugSection). This
doesn't work because some code relies on symbols having fragments to
indicate that they're defined, I think.
2) Canonicalize the MCSymbolData in RecordRelocation to be "first
fragment + absolute offset" so it would be cheaper to just test and
update the fragment in CompressDebugSections. This doesn't work because
the offset computed in RecordRelocation isn't that of the symbol's
fragment, it's the passed in fragment (I haven't figured out what that
fragment is - perhaps it's the location where the relocation is to be
written). And if the fragment offset has to be computed only for this
use we might as well just do it when we need to, in
CompressDebugSection.
I also added an assert to help catch this a bit more clearly, even
though it is UB. The test case improvements would either assert fail
and/or valgrind vail without the fix, even if they wouldn't necessarily
fail the FileCheck output.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/test/MC/ELF/compression.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=206653&r1=206652&r2=206653&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Apr 18 16:24:12 2014
@@ -616,6 +616,10 @@ static const MCSymbol *getBaseSymbol(con
void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD,
const MCAsmLayout &Layout) {
MCSymbolData &OrigData = *MSD.SymbolData;
+ assert(!OrigData.getFragment() ||
+ (&OrigData.getFragment()->getParent()->getSection() ==
+ &OrigData.getSymbol().getSection()) &&
+ "The symbol's section doesn't match the fragment's symbol");
const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
@@ -1244,6 +1248,19 @@ getCompressedFragment(MCAsmLayout &Layou
return CompressedFragment;
}
+static void UpdateSymbols(const MCAsmLayout &Layout, const MCSectionData &SD,
+ MCAssembler::symbol_range Symbols,
+ MCFragment *NewFragment) {
+ for (MCSymbolData &Data : Symbols) {
+ MCFragment *F = Data.getFragment();
+ if (F && F->getParent() == &SD) {
+ Data.setOffset(Data.getOffset() +
+ Layout.getFragmentOffset(Data.Fragment));
+ Data.setFragment(NewFragment);
+ }
+ }
+}
+
static void CompressDebugSection(MCAssembler &Asm, MCAsmLayout &Layout,
const MCSectionELF &Section,
MCSectionData &SD) {
@@ -1257,6 +1274,10 @@ static void CompressDebugSection(MCAssem
if (!CompressedFragment)
return;
+ // Update the fragment+offsets of any symbols referring to fragments in this
+ // section to refer to the new fragment.
+ UpdateSymbols(Layout, SD, Asm.symbols(), CompressedFragment.get());
+
// Invalidate the layout for the whole section since it will have new and
// different fragments now.
Layout.invalidateFragmentsFrom(&Fragments.front());
Modified: llvm/trunk/test/MC/ELF/compression.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=206653&r1=206652&r2=206653&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/compression.s (original)
+++ llvm/trunk/test/MC/ELF/compression.s Fri Apr 18 16:24:12 2014
@@ -1,6 +1,8 @@
-// RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu %s -o %t
+// RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu < %s -o %t
// RUN: llvm-objdump -s %t | FileCheck %s
// RUN: llvm-dwarfdump -debug-dump=abbrev %t | FileCheck --check-prefix=ABBREV %s
+// RUN: llvm-mc -filetype=obj -compress-debug-sections -triple i386-pc-linux-gnu < %s \
+// RUN: | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS %s
// REQUIRES: zlib
@@ -22,12 +24,21 @@
// ABBREV: Abbrev table for offset: 0x00000000
// ABBREV: [1] DW_TAG_compile_unit DW_CHILDREN_no
+// In x86 32 bit named symbols are used for temporary symbols in merge
+// sections, so make sure we handle symbols inside compressed sections
+// 386-SYMBOLS: Name: .Linfo_string0
+// 386-SYMBOLS-NOT: }
+// 386-SYMBOLS: Section: .zdebug_str
+
.section .debug_line,"", at progbits
.section .debug_abbrev,"", at progbits
+.Lsection_abbrev:
.byte 1 # Abbreviation Code
.byte 17 # DW_TAG_compile_unit
.byte 0 # DW_CHILDREN_no
+ .byte 27 # DW_AT_comp_dir
+ .byte 14 # DW_FORM_strp
.byte 0 # EOM(1)
.byte 0 # EOM(2)
.text
@@ -38,3 +49,15 @@ foo:
nop
.cfi_endproc
.cfi_sections .debug_frame
+
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+ .asciz "foo"
+
+ .section .debug_info,"", at progbits
+ .long 40 # Length of Unit
+ .short 4 # DWARF version number
+ .long .Lsection_abbrev # Offset Into Abbrev. Section
+ .byte 4 # Address Size (in bytes)
+ .byte 1 # Abbrev [1] DW_TAG_compile_unit
+ .long .Linfo_string0 # DW_AT_comp_dir
More information about the llvm-commits
mailing list