2018-03-14 15:44:23 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# RUN: echo "SECTIONS { \
|
|
|
|
# RUN: .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \
|
|
|
|
# RUN: .sec2 0x8800 : AT(0x8080) { sec2_start = .; *(.second_sec) sec2_end = .;} \
|
|
|
|
# RUN: }" > %t-lma.script
|
|
|
|
# RUN: not ld.lld -o %t.so --script %t-lma.script %t.o -shared 2>&1 | FileCheck %s -check-prefix LMA-OVERLAP-ERR
|
|
|
|
# LMA-OVERLAP-ERR: error: section .sec1 load address range overlaps with .sec2
|
2018-03-08 01:54:25 +08:00
|
|
|
# LMA-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]
|
|
|
|
# LMA-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8080, 0x817F]
|
2018-01-31 17:22:44 +08:00
|
|
|
|
2018-02-03 06:24:06 +08:00
|
|
|
# Check that we create the expected binary with --noinhibit-exec or --no-check-sections:
|
2018-01-31 17:22:44 +08:00
|
|
|
# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --noinhibit-exec
|
2018-02-07 08:41:34 +08:00
|
|
|
# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-check-sections -fatal-warnings
|
|
|
|
# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --check-sections --no-check-sections -fatal-warnings
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# Verify that the .sec2 was indeed placed in a PT_LOAD where the PhysAddr
|
|
|
|
# overlaps with where .sec1 is loaded:
|
|
|
|
# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-LMA
|
|
|
|
# BAD-LMA-LABEL: Section Headers:
|
2018-03-14 15:44:23 +08:00
|
|
|
# BAD-LMA: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1
|
|
|
|
# BAD-LMA: .sec2 PROGBITS 0000000000008800 002800 000100 00 WA 0 0 1
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-LMA-LABEL: Program Headers:
|
|
|
|
# BAD-LMA-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
2018-06-27 06:13:32 +08:00
|
|
|
# BAD-LMA-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000
|
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
|
|
|
# BAD-LMA-NEXT: LOAD 0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW 0x1000
|
2018-03-14 15:44:23 +08:00
|
|
|
# BAD-LMA-NEXT: LOAD 0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW 0x1000
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-LMA-LABEL: Section to Segment mapping:
|
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
|
|
|
# BAD-LMA: 01 .text .dynamic
|
|
|
|
# BAD-LMA: 02 .sec1
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# Now try a script where the virtual memory addresses overlap but ensure that the
|
|
|
|
# load addresses don't:
|
|
|
|
# RUN: echo "SECTIONS { \
|
|
|
|
# RUN: .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \
|
|
|
|
# RUN: .sec2 0x8020 : AT(0x8800) { sec2_start = .; *(.second_sec) sec2_end = .;} \
|
|
|
|
# RUN: }" > %t-vaddr.script
|
|
|
|
# RUN: not ld.lld -o %t.so --script %t-vaddr.script %t.o -shared 2>&1 | FileCheck %s -check-prefix VADDR-OVERLAP-ERR
|
|
|
|
# VADDR-OVERLAP-ERR: error: section .sec1 virtual address range overlaps with .sec2
|
2018-03-08 01:54:25 +08:00
|
|
|
# VADDR-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]
|
|
|
|
# VADDR-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8020, 0x811F]
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# Check that the expected binary was created with --noinhibit-exec:
|
|
|
|
# RUN: ld.lld -o %t.so --script %t-vaddr.script %t.o -shared --noinhibit-exec
|
|
|
|
# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-VADDR
|
|
|
|
# BAD-VADDR-LABEL: Section Headers:
|
2018-03-14 15:44:23 +08:00
|
|
|
# BAD-VADDR: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1
|
|
|
|
# BAD-VADDR: .sec2 PROGBITS 0000000000008020 003020 000100 00 WA 0 0 1
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-VADDR-LABEL: Program Headers:
|
|
|
|
# BAD-VADDR-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
2018-06-27 06:13:32 +08:00
|
|
|
# BAD-VADDR-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000
|
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
|
|
|
# BAD-VADDR-NEXT: LOAD 0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW 0x1000
|
2018-03-14 15:44:23 +08:00
|
|
|
# BAD-VADDR-NEXT: LOAD 0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW 0x1000
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-VADDR-LABEL: Section to Segment mapping:
|
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
|
|
|
# BAD-VADDR: 01 .text .dynamic
|
|
|
|
# BAD-VADDR: 02 .sec1
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# Finally check the case where both LMA and vaddr overlap
|
|
|
|
|
|
|
|
# RUN: echo "SECTIONS { \
|
|
|
|
# RUN: .sec1 0x8000 : { sec1_start = .; *(.first_sec) sec1_end = .;} \
|
|
|
|
# RUN: .sec2 0x8040 : { sec2_start = .; *(.second_sec) sec2_end = .;} \
|
|
|
|
# RUN: }" > %t-both-overlap.script
|
|
|
|
|
|
|
|
# RUN: not ld.lld -o %t.so --script %t-both-overlap.script %t.o -shared 2>&1 | FileCheck %s -check-prefix BOTH-OVERLAP-ERR
|
|
|
|
|
|
|
|
# BOTH-OVERLAP-ERR: error: section .sec1 file range overlaps with .sec2
|
[ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.
Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)
The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.
.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.
Reviewers: espindola, ruiu, pcc
Reviewed By: ruiu
Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58892
llvm-svn: 356226
2019-03-15 09:29:57 +08:00
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x2000, 0x20FF]
|
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x2040, 0x213F]
|
2018-01-31 17:22:44 +08:00
|
|
|
# BOTH-OVERLAP-ERR: error: section .sec1 virtual address range overlaps with .sec2
|
2018-03-08 01:54:25 +08:00
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]
|
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F]
|
2018-01-31 17:22:44 +08:00
|
|
|
# BOTH-OVERLAP-ERR: error: section .sec1 load address range overlaps with .sec2
|
2018-03-08 01:54:25 +08:00
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF]
|
|
|
|
# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F]
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# RUN: ld.lld -o %t.so --script %t-both-overlap.script %t.o -shared --noinhibit-exec
|
2018-03-14 15:44:23 +08:00
|
|
|
# Note: In case everything overlaps we create a binary with overlapping file
|
2018-01-31 17:22:44 +08:00
|
|
|
# offsets. ld.bfd seems to place .sec1 to file offset 18000 and .sec2
|
|
|
|
# at 18100 so that only virtual addr and LMA overlap
|
|
|
|
# However, in order to create such a broken binary the user has to ignore a
|
|
|
|
# fatal error by passing --noinhibit-exec, so this behaviour is fine.
|
|
|
|
|
|
|
|
# RUN: llvm-objdump -s %t.so | FileCheck %s -check-prefix BROKEN-OUTPUT-FILE
|
|
|
|
# BROKEN-OUTPUT-FILE-LABEL: Contents of section .sec1:
|
2018-03-14 15:44:23 +08:00
|
|
|
# BROKEN-OUTPUT-FILE-NEXT: 8000 01010101 01010101 01010101 01010101
|
|
|
|
# BROKEN-OUTPUT-FILE-NEXT: 8010 01010101 01010101 01010101 01010101
|
|
|
|
# BROKEN-OUTPUT-FILE-NEXT: 8020 01010101 01010101 01010101 01010101
|
|
|
|
# BROKEN-OUTPUT-FILE-NEXT: 8030 01010101 01010101 01010101 01010101
|
2018-01-31 17:22:44 +08:00
|
|
|
# Starting here the contents of .sec2 overwrites .sec1:
|
2018-03-14 15:44:23 +08:00
|
|
|
# BROKEN-OUTPUT-FILE-NEXT: 8040 02020202 02020202 02020202 02020202
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-BOTH
|
|
|
|
# BAD-BOTH-LABEL: Section Headers:
|
[ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.
Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)
The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.
.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.
Reviewers: espindola, ruiu, pcc
Reviewed By: ruiu
Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58892
llvm-svn: 356226
2019-03-15 09:29:57 +08:00
|
|
|
# BAD-BOTH: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1
|
|
|
|
# BAD-BOTH: .sec2 PROGBITS 0000000000008040 002040 000100 00 WA 0 0 1
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-BOTH-LABEL: Program Headers:
|
|
|
|
# BAD-BOTH-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
2018-06-27 06:13:32 +08:00
|
|
|
# BAD-BOTH-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000
|
[ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.
Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)
The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.
.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.
Reviewers: espindola, ruiu, pcc
Reviewed By: ruiu
Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58892
llvm-svn: 356226
2019-03-15 09:29:57 +08:00
|
|
|
# BAD-BOTH-NEXT: LOAD 0x001100 0x0000000000000100 0x0000000000000100 0x000070 0x000070 RW 0x1000
|
2018-01-31 17:22:44 +08:00
|
|
|
# BAD-BOTH-LABEL: Section to Segment mapping:
|
[ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.
Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)
The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.
.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.
Reviewers: espindola, ruiu, pcc
Reviewed By: ruiu
Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58892
llvm-svn: 356226
2019-03-15 09:29:57 +08:00
|
|
|
# BAD-BOTH: 01 .text .dynamic
|
2018-01-31 17:22:44 +08:00
|
|
|
|
|
|
|
.section .first_sec,"aw",@progbits
|
|
|
|
.rept 0x100
|
|
|
|
.byte 1
|
|
|
|
.endr
|
|
|
|
|
|
|
|
.section .second_sec,"aw",@progbits
|
|
|
|
.rept 0x100
|
|
|
|
.byte 2
|
|
|
|
.endr
|