-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[lld][ELF] Allow .data.rel.ro.unlikely
to be RELRO
#148920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mingmingl-llvm
wants to merge
5
commits into
main
Choose a base branch
from
users/mingmingl-llvm/lld
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
00b0ddb
allow data.rel.ro.unlikely as an relro section
mingmingl-llvm 9cdf86d
regard both .hot and .unlikely as section suffix if lld option keep-d…
mingmingl-llvm 27778e5
resolve comments
mingmingl-llvm eb439b1
omit ByName as suggested
mingmingl-llvm 3b23fde
apply suggestions
mingmingl-llvm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# REQUIRES: x86 | ||
|
||
# RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux input.s -o a.o | ||
|
||
# RUN: ld.lld -z keep-data-section-prefix -T linker-script.lds a.o -o a.out | ||
# RUN: llvm-readelf -l a.out | FileCheck --check-prefixes=SEG,LS %s | ||
# RUN: llvm-readelf -S a.out | FileCheck %s --check-prefix=CHECK-LS | ||
|
||
# RUN: ld.lld -z keep-data-section-prefix a.o -o b.out | ||
# RUN: llvm-readelf -l b.out | FileCheck --check-prefixes=SEG,PRE %s | ||
# RUN: llvm-readelf -S b.out | FileCheck %s --check-prefix=CHECK-PRE | ||
|
||
# RUN: ld.lld a.o -o c.out | ||
# RUN: llvm-readelf -l c.out | FileCheck --check-prefixes=SEG,PRE %s | ||
# RUN: llvm-readelf -S c.out | FileCheck %s --check-prefix=CHECK-PRE | ||
|
||
# RUN: not ld.lld -T linker-script.lds a.o -o d.out 2>&1 | FileCheck %s | ||
# CHECK: error: section: .relro_padding is not contiguous with other relro sections | ||
|
||
## The first RW PT_LOAD segment has FileSiz 0x126f (0x1000 + 0x200 + 0x60 + 0xf), | ||
## and its p_offset p_vaddr p_paddr p_filesz should match PT_GNU_RELRO. | ||
# Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align | ||
# SEG: LOAD 0x0001c8 0x00000000002011c8 0x00000000002011c8 0x000001 0x000001 R E 0x1000 | ||
# SEG-NEXT: LOAD 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x00126f 0x001e37 RW 0x1000 | ||
# SEG-NEXT: LOAD 0x001438 0x0000000000204438 0x0000000000204438 0x000001 0x000002 RW 0x1000 | ||
# SEG-NEXT: GNU_RELRO 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x00126f 0x001e37 R 0x1 | ||
# SEG-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0 | ||
|
||
## Input to output mapping per linker script | ||
## .data.rel.ro.split -> .data.rel.ro | ||
## .data.rel.ro -> .data.rel.ro | ||
## .data.rel.ro.hot -> .data.rel.ro.hot | ||
## .data.rel.ro.unlikely -> .data.rel.ro.unlikely | ||
# LS: .text | ||
# LS-NEXT: .data.rel.ro.hot .data.rel.ro .data.rel.ro.unlikely .relro_padding | ||
# LS-NEXT: .data .bss | ||
|
||
# [Nr] Name Type Address Off Size | ||
# CHECK-LS: .data.rel.ro.hot PROGBITS 00000000002021c9 0001c9 00000f | ||
# CHECK-LS-NEXT: .data.rel.ro PROGBITS 00000000002021d8 0001d8 000260 | ||
# CHECK-LS-NEXT: .data.rel.ro.unlikely PROGBITS 0000000000202438 000438 001000 | ||
# CHECK-LS-NEXT: .relro_padding NOBITS 0000000000203438 001438 000bc8 | ||
# CHECK-LS-NEXT: .data PROGBITS 0000000000204438 001438 000001 | ||
# CHECK-LS-NEXT: .bss NOBITS 0000000000204439 001439 000001 | ||
|
||
## Linker script is not provided to map data sections. | ||
## So all input sections with prefix .data.rel.ro will map to .data.rel.ro in the output. | ||
# PRE: .text | ||
# PRE-NEXT: .data.rel.ro .relro_padding | ||
# PRE-NEXT: .data .bss | ||
|
||
# [Nr] Name Type Address Off Size | ||
# CHECK-PRE: .data.rel.ro PROGBITS 00000000002021c9 0001c9 00126f | ||
# CHECK-PRE-NEXT: .relro_padding NOBITS 0000000000203438 001438 000bc8 | ||
# CHECK-PRE-NEXT: .data PROGBITS 0000000000204438 001438 000001 | ||
# CHECK-PRE-NEXT: .bss NOBITS 0000000000204439 001439 000001 | ||
|
||
#--- linker-script.lds | ||
SECTIONS { | ||
.data.rel.ro.hot : { *(.data.rel.ro.hot) } | ||
.data.rel.ro : { .data.rel.ro } | ||
.data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) } | ||
} INSERT AFTER .text | ||
|
||
|
||
#--- input.s | ||
.globl _start | ||
_start: | ||
ret | ||
|
||
.section .data.rel.ro.hot, "aw" | ||
.space 15 | ||
|
||
.section .data.rel.ro, "aw" | ||
.space 96 | ||
|
||
.section .data.rel.ro.split,"aw" | ||
.space 512 | ||
|
||
.section .data.rel.ro.unlikely, "aw" | ||
.space 4096 | ||
|
||
.section .data, "aw" | ||
.space 1 | ||
|
||
.section .bss, "aw" | ||
.space 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.