-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[ELF] -r/--emit-relocs: Fix crash when processing .rela.text before .text #156354
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3cc58a3
[lld][ELF] Fix crash when relocations proceed relocated section
mykouHW 2b54668
Merge branch 'main' into fix-orphan-sections-init
mykouHW f1e714b
Better fix for 156417
MaskRay cc33e42
delete old test
MaskRay 280cfd7
Merge branch 'main' into fix-orphan-sections-init
mykouHW 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # REQUIRES: x86 | ||
| # RUN: rm -rf %t && mkdir -p %t | ||
| # RUN: split-file %s %t && cd %t | ||
|
|
||
| ## Test that lld's orphan section placement can handle a relocatable link where | ||
| ## the relocation section is seen before the relocated section. | ||
|
|
||
| ## Create a relocatable object with the relocations before the relocated section | ||
| # RUN: llvm-mc -filetype=obj -triple=x86_64 foo.s -o foo.o | ||
| # RUN: ld.lld -r foo.o -T script.ld -o foo_mc.o | ||
|
|
||
| ## Rename the sections to make them orphans | ||
| # RUN: llvm-objcopy \ | ||
| # RUN: --rename-section .text=.com.text \ | ||
| # RUN: --rename-section .rela.text=.rela.com.text \ | ||
| # RUN: foo_mc.o foo_mc.o | ||
|
|
||
| # RUN: ld.lld -r foo_mc.o -T script.ld -o foo_mc_after.o | ||
| # RUN: llvm-readelf -S foo_mc_after.o | FileCheck %s | ||
| # CHECK: .com.text PROGBITS 0000000000000000 000040 000007 00 AX 0 0 16 | ||
| # CHECK-NEXT: .rela.com.text RELA 0000000000000000 000048 000018 18 I 4 1 8 | ||
|
|
||
| #--- foo.s | ||
| .text | ||
| .globl foo | ||
| .p2align 4 | ||
| .type foo,@function | ||
| foo: | ||
| mov $bar, %rax | ||
|
|
||
| #--- script.ld | ||
| SECTIONS | ||
| { | ||
| .rela.text 0 : { *(.rela.text) } | ||
| .text 0 : { *(.text) } | ||
| } | ||
|
|
||
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.
Could you add a comment to explain the test. Without context the steps look strange. LLD uses an additional comment character to distinguish comments from lit commands, so comment lines would start
##For example:
I tried to see if I could create the test case without llvm-objcopy but it seemed like I needed the linker script to have .rela.text as the pattern to get it to place first.
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.
The llvm-objcopy is unnecessary. Apply https://github.com/MaskRay/llvm-project/tree/lld-156354 to get the code/comment/test changes