[lld] r348291 - ELF: allow non allocated sections to go into allocated sections

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 10:47:45 PST 2018


Author: ruiu
Date: Tue Dec  4 10:47:44 2018
New Revision: 348291

URL: http://llvm.org/viewvc/llvm-project?rev=348291&view=rev
Log:
ELF: allow non allocated sections to go into allocated sections

Patch from Andrew Kelley.

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
    = .;
  }

Differential revision: https://reviews.llvm.org/D55276

Added:
    lld/trunk/test/ELF/linkerscript/merge-nonalloc.s
Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=348291&r1=348290&r2=348291&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Dec  4 10:47:44 2018
@@ -95,7 +95,7 @@ void OutputSection::addSection(InputSect
     Flags = IS->Flags;
   } else {
     // Otherwise, check if new type or flags are compatible with existing ones.
-    unsigned Mask = SHF_ALLOC | SHF_TLS | SHF_LINK_ORDER;
+    unsigned Mask = SHF_TLS | SHF_LINK_ORDER;
     if ((Flags & Mask) != (IS->Flags & Mask))
       error("incompatible section flags for " + Name + "\n>>> " + toString(IS) +
             ": 0x" + utohexstr(IS->Flags) + "\n>>> output section " + Name +

Added: lld/trunk/test/ELF/linkerscript/merge-nonalloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/merge-nonalloc.s?rev=348291&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-nonalloc.s (added)
+++ lld/trunk/test/ELF/linkerscript/merge-nonalloc.s Tue Dec  4 10:47:44 2018
@@ -0,0 +1,14 @@
+# 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,"", at progbits
+nonalloc_start:
+  .long 0xcafe




More information about the llvm-commits mailing list