llvm.org GIT mirror llvm / 037da24
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206653 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
2 changed file(s) with 45 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
615615 void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD,
616616 const MCAsmLayout &Layout) {
617617 MCSymbolData &OrigData = *MSD.SymbolData;
618 assert(!OrigData.getFragment() ||
619 (&OrigData.getFragment()->getParent()->getSection() ==
620 &OrigData.getSymbol().getSection()) &&
621 "The symbol's section doesn't match the fragment's symbol");
618622 const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
619623
620624 // This has to be in sync with when computeSymbolTable uses SHN_ABS or
12431247 return CompressedFragment;
12441248 }
12451249
1250 static void UpdateSymbols(const MCAsmLayout &Layout, const MCSectionData &SD,
1251 MCAssembler::symbol_range Symbols,
1252 MCFragment *NewFragment) {
1253 for (MCSymbolData &Data : Symbols) {
1254 MCFragment *F = Data.getFragment();
1255 if (F && F->getParent() == &SD) {
1256 Data.setOffset(Data.getOffset() +
1257 Layout.getFragmentOffset(Data.Fragment));
1258 Data.setFragment(NewFragment);
1259 }
1260 }
1261 }
1262
12461263 static void CompressDebugSection(MCAssembler &Asm, MCAsmLayout &Layout,
12471264 const MCSectionELF &Section,
12481265 MCSectionData &SD) {
12551272 // Leave the section as-is if the fragments could not be compressed.
12561273 if (!CompressedFragment)
12571274 return;
1275
1276 // Update the fragment+offsets of any symbols referring to fragments in this
1277 // section to refer to the new fragment.
1278 UpdateSymbols(Layout, SD, Asm.symbols(), CompressedFragment.get());
12581279
12591280 // Invalidate the layout for the whole section since it will have new and
12601281 // different fragments now.
None // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu %s -o %t
0 // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu < %s -o %t
11 // RUN: llvm-objdump -s %t | FileCheck %s
22 // RUN: llvm-dwarfdump -debug-dump=abbrev %t | FileCheck --check-prefix=ABBREV %s
3 // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple i386-pc-linux-gnu < %s \
4 // RUN: | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS %s
35
46 // REQUIRES: zlib
57
2123 // ABBREV: Abbrev table for offset: 0x00000000
2224 // ABBREV: [1] DW_TAG_compile_unit DW_CHILDREN_no
2325
26 // In x86 32 bit named symbols are used for temporary symbols in merge
27 // sections, so make sure we handle symbols inside compressed sections
28 // 386-SYMBOLS: Name: .Linfo_string0
29 // 386-SYMBOLS-NOT: }
30 // 386-SYMBOLS: Section: .zdebug_str
31
2432 .section .debug_line,"",@progbits
2533
2634 .section .debug_abbrev,"",@progbits
35 .Lsection_abbrev:
2736 .byte 1 # Abbreviation Code
2837 .byte 17 # DW_TAG_compile_unit
2938 .byte 0 # DW_CHILDREN_no
39 .byte 27 # DW_AT_comp_dir
40 .byte 14 # DW_FORM_strp
3041 .byte 0 # EOM(1)
3142 .byte 0 # EOM(2)
3243 .text
3748 nop
3849 .cfi_endproc
3950 .cfi_sections .debug_frame
51
52 .section .debug_str,"MS",@progbits,1
53 .Linfo_string0:
54 .asciz "foo"
55
56 .section .debug_info,"",@progbits
57 .long 40 # Length of Unit
58 .short 4 # DWARF version number
59 .long .Lsection_abbrev # Offset Into Abbrev. Section
60 .byte 4 # Address Size (in bytes)
61 .byte 1 # Abbrev [1] DW_TAG_compile_unit
62 .long .Linfo_string0 # DW_AT_comp_dir