This is an archive of the discontinued LLVM Phabricator instance.

[ MC ] Match labels to existing fragments even when switching sections.
ClosedPublic

Authored by mtrent on Dec 11 2019, 10:49 AM.

Details

Summary

This commit builds upon Derek Schuff's 2014 commit for attaching labels to
existing fragments ( Diff Revision: http://reviews.llvm.org/D5915 )

When temporary labels appear ahead of a fragment, MCObjectStreamer will
track the temporary label symbol in a "Pending Labels" list. Labels are
associated with fragments when a real fragment arrives; otherwise, an empty
data fragment will be created if the streamer's section changes or if the
stream finishes.

This commit moves the "Pending Labels" list into each MCStream, so that
this label-fragment matching process is resilient to section changes. If
the streamer emits a label in a new section, switches to another section to
do other work, then switches back to the first section and emits a
fragment, that initial label will be associated with this new fragment.
Labels will only receive empty data fragments in the case where no other
fragment exists for that section.

The downstream effects of this can be seen in Mach-O relocations. The
previous approach could produce local section relocations and external
symbol relocations for the same data in an object file, and this mix of
relocation types resulted in problems in the ld64 Mach-O linker. This
commit ensures relocations triggered by temporary labels are consistent.

Diff Detail

Event Timeline

mtrent created this revision.Dec 11 2019, 10:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2019, 10:49 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

pinging reviewers.

pete accepted this revision.Dec 16 2019, 12:52 PM

LGTM.

This revision is now accepted and ready to land.Dec 16 2019, 12:52 PM
dschuff accepted this revision.Dec 16 2019, 2:06 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka added inline comments.
llvm/include/llvm/MC/MCObjectStreamer.h
42

Never initialized?

hctim added a subscriber: hctim.Dec 17 2019, 3:06 PM
hctim added inline comments.
llvm/include/llvm/MC/MCObjectStreamer.h
42

Reverted in f827aff8598873194bccdfaf469f2dde7e5620d1 due to MSan failures.

MSan bots are hard to reproduce sometimes due to the multi-stage build. The easiest way to reproduce the problem is via. these instructions: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

An example failure is shown below:

==83120==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x3d5b7b1 in llvm::MCSection::flushPendingLabels(llvm::MCFragment*, unsigned long, unsigned int) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/MC/MCSection.cpp:102:9
    #1 0x3d4ee6e in insert /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/include/llvm/MC/MCObjectStreamer.h:77:5
    #2 0x3d4ee6e in llvm::MCObjectStreamer::getOrCreateDataFragment(llvm::MCSubtargetInfo const*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/MC/MCObjectStreamer.cpp:210:5
    #3 0x3d29f57 in llvm::MCELFStreamer::EmitInstToData(llvm::MCInst const&, llvm::MCSubtargetInfo const&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/MC/MCELFStreamer.cpp:584:10
    #4 0x298a7d4 in EmitAndCountInstruction /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/Target/X86/X86MCInstLower.cpp:103:16
    #5 0x298a7d4 in llvm::X86AsmPrinter::EmitInstruction(llvm::MachineInstr const*) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/Target/X86/X86MCInstLower.cpp:2552:3
    #6 0x42f02a6 in llvm::AsmPrinter::EmitFunctionBody() /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    #7 0x296c6b9 in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/Target/X86/X86AsmPrinter.cpp:79:3
    #8 0x5184e4e in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:13
    #9 0x3aaae8a in llvm::FPPassManager::runOnFunction(llvm::Function&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1481:27
    #10 0x3aabcdc in llvm::FPPassManager::runOnModule(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1517:16
    #11 0x3aad010 in runOnModule /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1582:27
    #12 0x3aad010 in llvm::legacy::PassManagerImpl::run(llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1694:44
    #13 0x3cb5b98 in (anonymous namespace)::codegen(llvm::lto::Config&, llvm::TargetMachine*, std::__1::function<std::__1::unique_ptr<llvm::lto::NativeObjectStream, std::__1::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, unsigned int, llvm::Module&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/LTO/LTOBackend.cpp:367:17
    #14 0x3cadb15 in llvm::lto::backend(llvm::lto::Config&, std::__1::function<std::__1::unique_ptr<llvm::lto::NativeObjectStream, std::__1::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, unsigned int, std::__1::unique_ptr<llvm::Module, std::__1::default_delete<llvm::Module> >, llvm::ModuleSummaryIndex&) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/LTO/LTOBackend.cpp:472:5
    #15 0x3c92b2a in llvm::lto::LTO::runRegularLTO(std::__1::function<std::__1::unique_ptr<llvm::lto::NativeObjectStream, std::__1::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/LTO/LTO.cpp:1015:10
    #16 0x3c90c9a in llvm::lto::LTO::run(std::__1::function<std::__1::unique_ptr<llvm::lto::NativeObjectStream, std::__1::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, std::__1::function<std::__1::function<std::__1::unique_ptr<llvm::lto::NativeObjectStream, std::__1::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)> (unsigned int, llvm::StringRef)>) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/LTO/LTO.cpp:945:18
    #17 0x63d1f2 in run(int, char**) /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/tools/llvm-lto2/llvm-lto2.cpp:349:13
    #18 0x631362 in main /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/tools/llvm-lto2/llvm-lto2.cpp:449:12
    #19 0x7fcd3aa132e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #20 0x5b4be9 in _start (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/llvm-lto2+0x5b4be9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/MC/MCSection.cpp:102:9 in llvm::MCSection::flushPendingLabels(llvm::MCFragment*, unsigned long, unsigned int)