Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/Target/CreateProgramHeaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,16 @@ bool GNULDBackend::createProgramHdrs() {
if (config().options().isOMagic())
cur_flag = (cur_flag & ~llvm::ELF::PF_W);

// getSegmentFlag returns 0 if the section is not allocatable.
if ((cur_flag != prev_flag) && (isCurAlloc))
createPT_LOAD = true;
if (!cur->isTBSS()) {
if ((cur_flag != prev_flag) && (isCurAlloc))
createPT_LOAD = true;

if (linkerScriptHasMemoryCommand && (cur_mem_region != prev_mem_region))
createPT_LOAD = true;
if (linkerScriptHasMemoryCommand && (cur_mem_region != prev_mem_region))
createPT_LOAD = true;

if (linkerScriptHasMemoryCommand && (cur_mem_region != prev_mem_region))
createPT_LOAD = true;
if (linkerScriptHasMemoryCommand && (cur_mem_region != prev_mem_region))
createPT_LOAD = true;
}

// If the current section is alloc section and if the previous section is
// NOBITS and current is PROGBITS, we need to create a new segment.
Expand Down Expand Up @@ -408,7 +409,7 @@ bool GNULDBackend::createProgramHdrs() {

// If Program headers are not specified and the vma difference is big
// lets create a PT_LOAD to adjust the offset.
if (std::abs(vmaoffset) > (int64_t)segAlign)
if ((std::abs(vmaoffset) > (int64_t)segAlign) && (!cur->isTBSS()))
createPT_LOAD = true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/AArch64/standalone/TLS_DESC/DESC.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ RUN: %link %linkopts -march aarch64 -static %t.o -z max-page-size=0x1000 -o %t.
RUN: llvm-objdump -d %t.out | %filecheck %s

#CHECK: {{.*}} <_test_tls_desc>:
#CHECK: {{.*}} adrp x0, 0x1000
#CHECK: {{.*}} ldr x0, [x0]
#CHECK: {{.*}} adrp x0, 0x0
#CHECK: {{.*}} ldr x0, [x0, #0x20]
#CHECK: {{.*}} <_test_tls_desc_local>:
#CHECK: {{.*}} adrp x0, 0x1000
#CHECK: {{.*}} ldr x0, [x0, #0x8]
#CHECK: {{.*}} adrp x0, 0x0
#CHECK: {{.*}} ldr x0, [x0, #0x28]
8 changes: 4 additions & 4 deletions test/AArch64/standalone/TLS_IE/IE.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ RUN: %clang %clangopts -target aarch64 %p/Inputs/f.c -c -o %t3.o
RUN: %link %linkopts -static -march aarch64 %t2.o %t3.o -z max-page-size=0x1000 -o %t2.out

CHECK: _test_tls_IE
CHECK: b0000000 adrp
CHECK: f9400000 ldr
CHECK: adrp x0, 0x0
CHECK: ldr x0, [x0, #0x10]
CHECK: _test_tls_IE_local
CHECK: d2a00000 movz
CHECK: f2800280 movk
CHECK: movz x0, #0x0
CHECK: movk x0, #0x14

14 changes: 14 additions & 0 deletions test/Common/standalone/TLS/OnlyTBSS/Inputs/script.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MEMORY
{
RAM (rw) : ORIGIN = 10000, LENGTH = 5000
}

SECTIONS {
.foo : { *(.text.foo) } > RAM
.empty : {} > RAM
tbss : { *(.tbss*) } > RAM
.empty : {} > RAM
.main : { *(.text.main) } > RAM
output_data : { BYTE(0x0) *(.data*) } > RAM
/DISCARD/ : { *(.riscv.attributes) }
}
16 changes: 16 additions & 0 deletions test/Common/standalone/TLS/OnlyTBSS/Inputs/scripttbssnewregion.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MEMORY
{
RAM (rw) : ORIGIN = 10000, LENGTH = 5000
ROM (rw) : ORIGIN = 20000, LENGTH = 5000
}

SECTIONS {
.foo : { *(.text.foo) } > RAM
.empty : {} > RAM
tdata : { *(.tdata*) } > ROM
tbss : { *(.tbss*) } > ROM
.empty : {} > ROM
.main : { *(.text.main) } > ROM
output_data : { BYTE(0x0) *(.data*) } > ROM
/DISCARD/ : { *(.riscv.attributes) }
}
4 changes: 4 additions & 0 deletions test/Common/standalone/TLS/OnlyTBSS/Inputs/tls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__thread int b = 0;
int data = 100;
int foo() { return 0; }
int main() { return 0; }
14 changes: 14 additions & 0 deletions test/Common/standalone/TLS/OnlyTBSS/OnlyTBSS.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
UNSUPPORTED: ndk-build
#---OnlyTBSS.test--------------------------- Executable -----------------#
#BEGIN_COMMENT
# This tests that using TBSS only does not create an empty segment
#END_COMMENT
#START_TEST
RUN: %clang %clangopts -c %p/Inputs/tls.c -o %t1.1.o -fdata-sections -ftls-model=local-exec -fPIE
RUN: %link %linkopts %t1.1.o -T %p/Inputs/script.t -o %t.out --defsym __aeabi_read_tp=0
RUN: %readelf -l -W %t.out | %filecheck %s -check-prefix=EMPTYLOAD
RUN: %link %linkopts %t1.1.o -T %p/Inputs/scripttbssnewregion.t -o %t.out --defsym __aeabi_read_tp=0
RUN: %readelf -l -W %t.out | %filecheck %s -check-prefix=EMPTYLOAD
#END_TEST

#EMPTYLOAD-NOT: LOAD {{.*}} {{.*}} {{.*}} 0x{{[0]+}} 0x{{[0]+}} {{.*}}
2 changes: 0 additions & 2 deletions test/Hexagon/TLS/headers/headers.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ RUN: %readelf -l -S -s -W %t6.out | %filecheck %s --check-prefix="TBSSDATA"
#ALL: 00000008 4 TLS GLOBAL DEFAULT {{[0-9]}} b
#TBSSTDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x1000
#TBSSTDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TBSS: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} R E 0x1000
#TBSS: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00000 0x00008 R 0x8
#TDATADATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00008 0x00008 RW 0x1000
#TDATADATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x1000
#TDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TBSSDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x1000
#TBSSDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00000 0x00008 R 0x8

2 changes: 0 additions & 2 deletions test/Hexagon/linux/TLS/headers/headers.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ RUN: %readelf -l -S -s -W %t6.out | %filecheck %s --check-prefix="TBSSDATA"
#ALL: 00000008 4 TLS GLOBAL DEFAULT {{[0-9]}} b
#TBSSTDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x10000
#TBSSTDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TBSS: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} R E 0x10000
#TBSS: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00000 0x00008 R 0x8
#TDATADATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00008 0x00008 RW 0x10000
#TDATADATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x10000
#TDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00008 R 0x8
#TBSSDATA: LOAD {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00004 0x00004 RW 0x10000
#TBSSDATA: TLS {{[x0-9a-z]+}} {{[x0-9a-z]+}} {{[x0-9a-z]+}} 0x00000 0x00008 R 0x8

Loading