This is an archive of the discontinued LLVM Phabricator instance.

ELF: allow non allocated sections to go into allocated sections
ClosedPublic

Authored by andrewrk on Dec 4 2018, 8:41 AM.

Details

Summary

For context, see https://bugs.llvm.org/show_bug.cgi?id=39862

The use case is embedded / OS programming where the kernel wants
access to its own debug info via mapped dwarf info. I have a proof of
concept of this working, using this linker script snippet:

.rodata : ALIGN(4K) {
    *(.rodata)
    __debug_info_start = .;
    KEEP(*(.debug_info))
    __debug_info_end = .;
    __debug_abbrev_start = .;
    KEEP(*(.debug_abbrev))
    __debug_abbrev_end = .;
    __debug_str_start = .;
    KEEP(*(.debug_str))
    __debug_str_end = .;
    __debug_line_start = .;
    KEEP(*(.debug_line))
    __debug_line_end = .;
    __debug_ranges_start = .;
    KEEP(*(.debug_ranges))
    __debug_ranges_end = .;
}

Thanks Rui for writing the test for me.

Diff Detail

Repository
rL LLVM

Event Timeline

andrewrk created this revision.Dec 4 2018, 8:41 AM
ruiu accepted this revision.Dec 4 2018, 10:32 AM

LGTM.

Please add this as a test.

$ cat lld/test/ELF/linkerscript/merge-nonalloc.s
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { .text : { *(.text) *(.nonalloc) } }" > %t.script
# RUN: ld.lld -shared -o %t.exe %t.script %t.o
# RUN: llvm-objdump -syms %t.exe | FileCheck %s

# CHECK: .text 00000000 nonalloc_start

_start:
  nop

.section .nonalloc,"",@progbits
nonalloc_start:
  .long 0xcafe
This revision is now accepted and ready to land.Dec 4 2018, 10:32 AM
andrewrk updated this revision to Diff 176673.Dec 4 2018, 10:40 AM
andrewrk edited the summary of this revision. (Show Details)

Added Rui's test case. Thank you for helping me with that. Please note that I do not have commit privileges and so someone will have to merge this on my behalf.

This revision was automatically updated to reflect the committed changes.