This is an archive of the discontinued LLVM Phabricator instance.

[RuntimeDyld] Fix debug section relocation (pr20457)
ClosedPublic

Authored by labath on May 5 2017, 3:58 AM.

Details

Summary

Debug info sections, (or non-SHF_ALLOC sections in general) should be
linked as if their load address was zero to emulate the behavior of the
static linker.

I've made two tests for this: One checks that we are able to properly
process Modules with debug info in the ProcessAllSections mode. This
tests the feature only indirectly, by making sure we don't assert when
processing relocations, and it only does that on x86_64 linux builds
with asserts.

The second test directly verifies that the relocations were applied correctly,
by directly inspecting the generated sections. This one works on all platforms,
but it is a little cumbersome due to the need to construct a section with
well-defined contents. Nonetheless, most of the code is boilerplate, and it
could be shared if we end up having more tests like these.

This bug was discovered because it was breaking lldb expression evaluation on
linux.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.May 5 2017, 3:58 AM
lhames requested changes to this revision.May 7 2017, 10:42 AM

Hi Pavel,

This should be an llvm-rtdyld lit test (the unit-test is impressive, but this is RuntimeDyld specific so llvm-rtdyld is more appropriate). I've modified llvm-rtdyld and RuntimeDyldChecker in r302372 to make it possible to test this:

# RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj -o %T/ELF_x86-64_debug_frame.o %s
# RUN: llvm-rtdyld -triple=x86_64-pc-linux -verify -check=%s %T/ELF_x86-64_debug_frame.o

        .text
        .file   "debug_frame_test.c"
        .align  16, 0x90
        .type   foo,@function
foo:
        .cfi_startproc
        retq
.Ltmp0:
        .size   foo, .Ltmp0-foo
        .cfi_endproc
        .cfi_sections .debug_frame

# Check that .debug_frame is mapped to 0.
# rtdyld-check: section_addr(ELF_x86-64_debug_frame.o, .debug_frame) = 0

# Check that The relocated FDE's CIE offset also points to zero.
# rtdyld-check: *{4}(section_addr(ELF_x86-64_debug_frame.o, .debug_frame) + 0x1C) = 0

This should be added as llvm/test/ExecutionEngine/RuntimeDyld/X86/ELF_x86-64_debug_frame.s, replacing the unit test.

Cheers,
Lang.

This revision now requires changes to proceed.May 7 2017, 10:42 AM
labath updated this revision to Diff 98967.May 15 2017, 2:59 AM
labath edited edge metadata.

Add llvm-rtdyld test case

Thanks for the help, this definitely looks much better. :)

Since I already have it written, would you still be interested in the ProcessAllSections MCJIT test by any chance? I noticed that you none of the MCJIT tests set ProcessAllSections=true, or use Modules with debug info, so I think it has some value for smoke testing parts these parts of the pipeline (and it is nowhere near as ugly as the other create-an-.o-file-by hand test :) ).

lhames accepted this revision.May 16 2017, 9:29 AM

LGTM. :)

And yes - I think it's reasonable to add that MCJIT unit test case too.

Thanks for working on this!

This revision is now accepted and ready to land.May 16 2017, 9:29 AM
This revision was automatically updated to reflect the committed changes.