-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[ELF] Add support for CREL locations for SHT_LLVM_BB_ADDR_MAP #126446
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
boomanaiden154
merged 6 commits into
main
from
users/boomanaiden154/elf-add-support-for-crel-locations-for-sht_llvm_bb_addr_map
Feb 10, 2025
Merged
[ELF] Add support for CREL locations for SHT_LLVM_BB_ADDR_MAP #126446
boomanaiden154
merged 6 commits into
main
from
users/boomanaiden154/elf-add-support-for-crel-locations-for-sht_llvm_bb_addr_map
Feb 10, 2025
Conversation
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
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
Member
|
@llvm/pr-subscribers-llvm-binary-utilities Author: Aiden Grossman (boomanaiden154) ChangesThis patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP Full diff: https://github.com/llvm/llvm-project/pull/126446.diff 2 Files Affected:
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 8cb3d7eb141766d..bf42c92a242a160 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -747,20 +747,25 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
assert(RelaSec &&
"Can't read a SHT_LLVM_BB_ADDR_MAP section in a relocatable "
"object file without providing a relocation section.");
- // We might end up with relocations in CREL here. If we do, return an
- // error since we do not currently support them.
- if (RelaSec->sh_type == ELF::SHT_CREL)
- return createError("unable to read relocations for section " +
- describe(EF, Sec) +
- " as the corresponding relocation section format is "
- "CREL, which is not currently supported.");
- Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas = EF.relas(*RelaSec);
- if (!Relas)
- return createError("unable to read relocations for section " +
- describe(EF, Sec) + ": " +
- toString(Relas.takeError()));
- for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas)
- FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
+ if (RelaSec->sh_type == ELF::SHT_CREL) {
+ Expected<typename ELFFile<ELFT>::RelsOrRelas> Relas = EF.crels(*RelaSec);
+ if (!Relas)
+ return createError("unable to read CREL relocations for section " +
+ describe(EF, Sec) + ": " +
+ toString(Relas.takeError()));
+ for (typename ELFFile<ELFT>::Elf_Rela Rela : std::get<1>(*Relas)) {
+ FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
+ }
+ } else {
+ Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas =
+ EF.relas(*RelaSec);
+ if (!Relas)
+ return createError("unable to read relocations for section " +
+ describe(EF, Sec) + ": " +
+ toString(Relas.takeError()));
+ for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas)
+ FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
+ }
}
auto GetAddressForRelocation =
[&](unsigned RelocationOffsetInSection) -> Expected<unsigned> {
diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
index e7f78491a94737a..325a956e78591bb 100644
--- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
@@ -1,7 +1,8 @@
## This test checks how we handle the --bb-addr-map option on relocatable
## object files.
-# RUN: yaml2obj %s -o %t1.o
+# RUN: yaml2obj -D RELOCATION_SECTION_NAME=.rela.llvm_bb_addr_map \
+# RUN: -D RELOCATION_SECTION_TYPE=SHT_RELA %s -o %t1.o
# RUN: llvm-readobj %t1.o --bb-addr-map | FileCheck %s
# CHECK: BBAddrMap [
@@ -77,8 +78,8 @@ Sections:
AddressOffset: 0x0
Size: 0x11
Metadata: 0x8
- - Name: .rela.llvm_bb_addr_map
- Type: SHT_RELA
+ - Name: [[RELOCATION_SECTION_NAME]]
+ Type: [[RELOCATION_SECTION_TYPE]]
Flags: [ SHF_INFO_LINK ]
Link: .symtab
Info: .llvm_bb_addr_map
@@ -228,3 +229,55 @@ Sections:
# ET-DYN-NO-WARNING: ]
# ET-DYN-NO-WARNING: }
# ET-DYN-NO-WARNING: ]
+
+## Check that we can correctly decode a BBAddrMap in a reloctable object file
+## with CREL relocations.
+
+# RUN: yaml2obj -D RELOCATION_SECTION_NAME=.crel.llvm_bb_addr_map \
+# RUN: -D RELOCATION_SECTION_TYPE=SHT_CREL %s -o %t6.o
+# RUN: llvm-readobj %t6.o --bb-addr-map | FileCheck %s --check-prefix=CREL
+
+# CREL: BBAddrMap [
+# CREL-NEXT: Function {
+# CREL-NEXT: At: 0x0
+# CREL-NEXT: Name: <?>
+# CREL-NEXT: BB Ranges [
+# CREL-NEXT: {
+# CREL-NEXT: Base Address: 0x0
+# CREL-NEXT: BB Entries [
+# CREL-NEXT: {
+# CREL-NEXT: ID: 0
+# CREL-NEXT: Offset: 0x0
+# CREL-NEXT: Size: 0xF
+# CREL-NEXT: HasReturn: Yes
+# CREL-NEXT: HasTailCall: No
+# CREL-NEXT: IsEHPad: No
+# CREL-NEXT: CanFallThrough: No
+# CREL-NEXT: HasIndirectBranch: No
+# CREL-NEXT: }
+# CREL-NEXT: ]
+# CREL-NEXT: }
+# CREL-NEXT: ]
+# CREL-NEXT: }
+# CREL-NEXT: Function {
+# CREL-NEXT: At: 0x10
+# CREL-NEXT: Name: <?>
+# CREL-NEXT: BB Ranges [
+# CREL-NEXT: {
+# CREL-NEXT: Base Address: 0x10
+# CREL-NEXT: BB Entries [
+# CREL-NEXT: {
+# CREL-NEXT: ID: 0
+# CREL-NEXT: Offset: 0x0
+# CREL-NEXT: Size: 0x11
+# CREL-NEXT: HasReturn: No
+# CREL-NEXT: HasTailCall: No
+# CREL-NEXT: IsEHPad: No
+# CREL-NEXT: CanFallThrough: Yes
+# CREL-NEXT: HasIndirectBranch: No
+# CREL-NEXT: }
+# CREL-NEXT: ]
+# CREL-NEXT: }
+# CREL-NEXT: ]
+# CREL-NEXT: }
+# CREL-NEXT: ]
|
Contributor
Author
|
This is a stacked PR on top of #126445. |
boomanaiden154
added a commit
to boomanaiden154/llvm-project
that referenced
this pull request
Feb 10, 2025
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP sections in relocatable object files when the relocation format is CREL. Pull Request: llvm#126446
MaskRay
approved these changes
Feb 10, 2025
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
github-actions bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Feb 10, 2025
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP sections in relocatable object files when the relocation format is CREL. Reviewers: rlavaee, jh7370, red1bluelost, MaskRay Reviewed By: MaskRay Pull Request: llvm/llvm-project#126446
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP sections in relocatable object files when the relocation format is CREL. Reviewers: rlavaee, jh7370, red1bluelost, MaskRay Reviewed By: MaskRay Pull Request: llvm#126446
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 14, 2025
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP sections in relocatable object files when the relocation format is CREL. Reviewers: rlavaee, jh7370, red1bluelost, MaskRay Reviewed By: MaskRay Pull Request: llvm#126446
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Feb 24, 2025
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP sections in relocatable object files when the relocation format is CREL. Reviewers: rlavaee, jh7370, red1bluelost, MaskRay Reviewed By: MaskRay Pull Request: llvm#126446
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP
sections in relocatable object files when the relocation format is CREL.