-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[LLD][ELF][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (3/3) #125689
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
796adea
[LLD][ELF][AArch64] Add support for SHF_AARCH64_PURECODE ELF section …
Il-Capitano 53b6bdf
Address some review feedback
Il-Capitano 282ba84
Add tests for -z execute-only-report
Il-Capitano d1032b4
Address review feedback from MaskRay
Il-Capitano 30ee1a7
Move -z execute-only-report checking into Writer.cpp
Il-Capitano 0697de0
Resolve merge conflicts after rebase
Il-Capitano 35b0fd5
Remove `-z execute-only-report`
Il-Capitano f95bee6
Add execute-only compatible thunks
Il-Capitano 0bc840d
Address review feedback
Il-Capitano 50d26bd
Address review feedback
Il-Capitano e0358eb
improve test
MaskRay 548d5dc
Add test for a BTI landing pad target in execute-only thunks
Il-Capitano d160ea3
Merge aarch64-call26-thunk-execute-only.s and aarch64-jump26-thunk-ex…
Il-Capitano 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,32 @@ | ||
// REQUIRES: aarch64 | ||
Il-Capitano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o | ||
// RUN: ld.lld %t.o -o %t.so -shared | ||
// RUN: llvm-readelf -l %t.so | FileCheck --implicit-check-not=LOAD %s | ||
|
||
// RUN: echo ".section .foo,\"ax\"; ret" > %t.s | ||
// RUN: llvm-mc -filetype=obj -triple=aarch64 %t.s -o %t2.o | ||
// RUN: ld.lld %t.o %t2.o -o %t.so -shared | ||
// RUN: llvm-readelf -l %t.so | FileCheck --check-prefix=DIFF --implicit-check-not=LOAD %s | ||
|
||
// CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000245 0x000245 R 0x10000 | ||
// CHECK-NEXT: LOAD 0x000248 0x0000000000010248 0x0000000000010248 0x{{.*}} 0x{{.*}} R E 0x10000 | ||
// CHECK-NEXT: LOAD 0x00024c 0x000000000002024c 0x000000000002024c 0x{{.*}} 0x{{.*}} E 0x10000 | ||
// CHECK-NEXT: LOAD 0x000250 0x0000000000030250 0x0000000000030250 0x000070 0x000db0 RW 0x10000 | ||
|
||
// CHECK: 01 .dynsym .gnu.hash .hash .dynstr | ||
// CHECK-NEXT: 02 .text | ||
// CHECK-NEXT: 03 .foo | ||
// CHECK-NEXT: 04 .dynamic | ||
|
||
// DIFF: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x00020d 0x00020d R 0x10000 | ||
// DIFF-NEXT: LOAD 0x000210 0x0000000000010210 0x0000000000010210 0x00000c 0x00000c R E 0x10000 | ||
// DIFF-NEXT: LOAD 0x000220 0x0000000000020220 0x0000000000020220 0x000070 0x000de0 RW 0x10000 | ||
|
||
// DIFF: 01 .dynsym .gnu.hash .hash .dynstr | ||
// DIFF-NEXT: 02 .text .foo | ||
// DIFF-NEXT: 03 .dynamic | ||
|
||
ret | ||
.section .foo,"axy" | ||
ret |
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,75 @@ | ||
// REQUIRES: aarch64 | ||
// RUN: rm -rf %t && split-file %s %t && cd %t | ||
// RUN: llvm-mc -filetype=obj -triple=aarch64 asm -o a.o | ||
// RUN: ld.lld --script=lds a.o -o exe --defsym absolute=0xf0000000 | ||
// RUN: llvm-objdump -d --no-show-raw-insn exe | FileCheck %s | ||
|
||
//--- asm | ||
.section ".note.gnu.property", "a" | ||
.p2align 3 | ||
.long 4 | ||
.long 0x10 | ||
.long 0x5 | ||
.asciz "GNU" | ||
|
||
/// Enable BTI. | ||
.long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND. | ||
.long 4 | ||
.long 1 // GNU_PROPERTY_AARCH64_FEATURE_1_BTI. | ||
.long 0 | ||
|
||
.section .text.0,"axy",@progbits | ||
.global _start | ||
.type _start,@function | ||
_start: | ||
/// Expect thunk to target a linker generated entry point with BTI landing pad. | ||
/// Two calls to make sure only one landing pad is created. | ||
bl fn1 | ||
b fn1 | ||
/// No BTI landing pad is added for absolute symbols. | ||
bl absolute | ||
|
||
/// This function does not have a BTI compatible landing pad. Expect a linker | ||
/// generated landing pad for indirect branch thunks. | ||
.section .text.1,"axy",@progbits | ||
.hidden fn1 | ||
.type fn1,@function | ||
fn1: | ||
ret | ||
|
||
// CHECK-LABEL: <_start>: | ||
// CHECK-NEXT: 18001000: bl 0x1800100c <__AArch64AbsXOLongThunk_> | ||
// CHECK-NEXT: b 0x1800100c <__AArch64AbsXOLongThunk_> | ||
// CHECK-NEXT: bl 0x18001020 <__AArch64AbsXOLongThunk_absolute> | ||
|
||
// CHECK-LABEL: <__AArch64AbsXOLongThunk_>: | ||
// CHECK-NEXT: 1800100c: mov x16, #0x0 | ||
// CHECK-NEXT: movk x16, #0x3000, lsl #16 | ||
// CHECK-NEXT: movk x16, #0x0, lsl #32 | ||
// CHECK-NEXT: movk x16, #0x0, lsl #48 | ||
// CHECK-NEXT: br x16 | ||
|
||
// CHECK-LABEL: <__AArch64AbsXOLongThunk_absolute>: | ||
// CHECK-NEXT: 18001020: mov x16, #0x0 | ||
// CHECK-NEXT: movk x16, #0xf000, lsl #16 | ||
// CHECK-NEXT: movk x16, #0x0, lsl #32 | ||
// CHECK-NEXT: movk x16, #0x0, lsl #48 | ||
// CHECK-NEXT: br x16 | ||
|
||
// CHECK-LABEL: <__AArch64BTIThunk_>: | ||
// CHECK-NEXT: 30000000: bti c | ||
|
||
// CHECK-LABEL: <fn1>: | ||
// CHECK-NEXT: 30000004: ret | ||
|
||
//--- lds | ||
PHDRS { | ||
low PT_LOAD FLAGS(0x1 | 0x4); | ||
mid PT_LOAD FLAGS(0x1 | 0x4); | ||
high PT_LOAD FLAGS(0x1 | 0x4); | ||
} | ||
SECTIONS { | ||
.rodata 0x10000000 : { *(.note.gnu.property) } :low | ||
.text 0x18001000 : { *(.text.0) } :mid | ||
.text_high 0x30000000 : { *(.text.*) } :high | ||
} |
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,22 @@ | ||
// REQUIRES: aarch64 | ||
// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o | ||
// RUN: ld.lld %t.o --defsym big=0x1111222233334444 -o %t | ||
// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s | ||
|
||
.section .text,"axy",@progbits,unique,0 | ||
.globl _start | ||
_start: | ||
bl big | ||
b big | ||
|
||
// CHECK: Disassembly of section .text: | ||
// CHECK-EMPTY: | ||
// CHECK-LABEL: <_start>: | ||
// CHECK-NEXT: bl {{.*}} <__AArch64AbsXOLongThunk_big> | ||
// CHECK-NEXT: b {{.*}} <__AArch64AbsXOLongThunk_big> | ||
// CHECK-LABEL: <__AArch64AbsXOLongThunk_big>: | ||
// CHECK-NEXT: mov x16, #0x4444 | ||
// CHECK-NEXT: movk x16, #0x3333, lsl #16 | ||
// CHECK-NEXT: movk x16, #0x2222, lsl #32 | ||
// CHECK-NEXT: movk x16, #0x1111, lsl #48 | ||
// CHECK-NEXT: br x16 |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could rewrite as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to above, I didn't want to mix flags from different architectures, even though they have the same value.