119 lines · plain
1REQUIRES: x862 3RUN: split-file %s %ts4RUN: llvm-mc -filetype=obj -triple=x86_64 %ts/s -o %t.o5 6## Check that despite having a lower sort rank, an orphan section '.init_array'7## is placed after '.data' and '.data2' and in the same memory region.8 9## Also check that a non-SHF_ALLOC orphan section '.nonalloc' is not placed in10## a memory region. Both defined memory regions are exhausted after all expected11## sections are added, thus, trying to put any unexpected section would lead to12## an error.13 14RUN: ld.lld -o %t -T %ts/t %t.o15RUN: llvm-readelf -S %t | FileCheck %s16 17CHECK: Name Type Address Off Size18CHECK: .text PROGBITS 0000000000008000 {{[0-9a-f]+}} 00000419CHECK: .data PROGBITS 0000000000009000 {{[0-9a-f]+}} 00000820CHECK: .data2 PROGBITS 0000000000009008 {{[0-9a-f]+}} 00000c21CHECK: .init_array INIT_ARRAY 0000000000009014 {{[0-9a-f]+}} 00001022CHECK: .nonalloc PROGBITS 0000000000000000 {{[0-9a-f]+}} 00001023 24## Check that attributes of memory regions are ignored for orphan sections when25## the anchor section specifies the memory region explicitly, This seems to26## contradict https://sourceware.org/binutils/docs/ld/MEMORY.html, but better27## resembles the way GNU ld actually works.28 29RUN: ld.lld -o %t2 -T %ts/t2 %t.o30RUN: llvm-readelf -S %t2 | FileCheck %s31 32## Same as the previous case, but now properties of sections conflict with33## memory region attributes. Still, orphan sections are placed in the same34## regions as their anchors.35 36RUN: ld.lld -o %t3 -T %ts/t3 %t.o37RUN: llvm-readelf -S %t3 | FileCheck %s38 39## Check that when memory regions for anchor sections are not specified40## explicitly and are selected by attributes, orphan sections are also assigned41## to memory regions by matching properties.42 43RUN: ld.lld -o %t4 -T %ts/t4 %t.o44RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=CHECK445 46CHECK4: Name Type Address Off Size47CHECK4: .text PROGBITS 0000000000008000 {{[0-9a-f]+}} 00000448CHECK4: .init_array INIT_ARRAY 0000000000009000 {{[0-9a-f]+}} 00001049CHECK4: .data PROGBITS 0000000000009010 {{[0-9a-f]+}} 00000850CHECK4: .data2 PROGBITS 0000000000009018 {{[0-9a-f]+}} 00000c51CHECK4: .nonalloc PROGBITS 0000000000000000 {{[0-9a-f]+}} 00001052 53#--- s54 .text55 .zero 456 57 .data58 .zero 859 60 .section .data2,"aw",@progbits61 .zero 0xc62 63 .section .init_array,"aw",@init_array64 .zero 0x1065 66 .section .nonalloc,""67 .zero 0x1068 69#--- t70MEMORY71{72 TEXT : ORIGIN = 0x8000, LENGTH = 0x473 DATA : ORIGIN = 0x9000, LENGTH = 0x2474}75 76SECTIONS77{78 .text : { *(.text) } > TEXT79 .data : { *(.data) } > DATA80}81 82#--- t283MEMORY84{85 TEXT (rwx) : ORIGIN = 0x8000, LENGTH = 0x486 DATA (rwx) : ORIGIN = 0x9000, LENGTH = 0x2487}88 89SECTIONS90{91 .text : { *(.text) } > TEXT92 .data : { *(.data) } > DATA93}94 95#--- t396MEMORY97{98 TEXT (!w) : ORIGIN = 0x8000, LENGTH = 0x499 DATA (!w) : ORIGIN = 0x9000, LENGTH = 0x24100}101 102SECTIONS103{104 .text : { *(.text) } > TEXT105 .data : { *(.data) } > DATA106}107 108#--- t4109MEMORY110{111 TEXT (rx) : ORIGIN = 0x8000, LENGTH = 0x4112 DATA (w!x) : ORIGIN = 0x9000, LENGTH = 0x24113}114 115SECTIONS116{117 .text : { *(.text) }118}119