-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[lld] Sort code section chunks by range types on Arm64EC targets. #69099
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,7 @@ class Writer { | |
void locateImportTables(); | ||
void createExportTable(); | ||
void mergeSections(); | ||
void sortECChunks(); | ||
void removeUnusedSections(); | ||
void assignAddresses(); | ||
bool isInRange(uint16_t relType, uint64_t s, uint64_t p, int margin); | ||
|
@@ -676,6 +677,7 @@ void Writer::run() { | |
createMiscChunks(); | ||
createExportTable(); | ||
mergeSections(); | ||
sortECChunks(); | ||
removeUnusedSections(); | ||
finalizeAddresses(); | ||
removeEmptySections(); | ||
|
@@ -1377,6 +1379,21 @@ void Writer::mergeSections() { | |
} | ||
} | ||
|
||
// EC targets may have chunks of various architectures mixed together at this | ||
// point. Group code chunks of the same architecture together by sorting chunks | ||
// by their EC range type. | ||
void Writer::sortECChunks() { | ||
if (!isArm64EC(ctx.config.machine)) | ||
return; | ||
|
||
for (OutputSection *sec : ctx.outputSections) { | ||
if (sec->isCodeSection()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right, here's a new call to the recently refactored function, sorry I didn't see it before. That makes the coupling much clearer. |
||
llvm::stable_sort(sec->chunks, [=](const Chunk *a, const Chunk *b) { | ||
return a->getArm64ECRangeType() < b->getArm64ECRangeType(); | ||
}); | ||
} | ||
} | ||
|
||
// Visits all sections to assign incremental, non-overlapping RVAs and | ||
// file offsets. | ||
void Writer::assignAddresses() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
.section .rdata,"dr" | ||
.globl _load_config_used | ||
.p2align 3, 0 | ||
_load_config_used: | ||
.word 0x140 | ||
.fill 0x54, 1, 0 | ||
.xword __security_cookie | ||
.fill 0x10, 1, 0 | ||
.xword __guard_check_icall_fptr | ||
.xword __guard_dispatch_icall_fptr | ||
.xword __guard_fids_table | ||
.xword __guard_fids_count | ||
.xword __guard_flags | ||
.xword 0 | ||
.xword __guard_iat_table | ||
.xword __guard_iat_count | ||
.xword __guard_longjmp_table | ||
.xword __guard_longjmp_count | ||
.xword 0 | ||
.xword __chpe_metadata | ||
.fill 0x78, 1, 0 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MS places the call helpers in the .cfg00 section, should that also be done here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that we will want to do that ultimately, but note that link.exe automatically merges .cfg00 section to .rdata, so it doesn't really change the output (it possibly changes the layout of .rdata itself). I think that we will want to do that merge in lld-link as well and then change the test. |
||
__guard_check_icall_fptr: | ||
.xword 0 | ||
__guard_dispatch_icall_fptr: | ||
.xword 0 | ||
__os_arm64x_dispatch_call_no_redirect: | ||
.xword 0 | ||
__os_arm64x_dispatch_ret: | ||
.xword 0 | ||
__os_arm64x_check_call: | ||
.xword 0 | ||
__os_arm64x_check_icall: | ||
.xword 0 | ||
__os_arm64x_get_x64_information: | ||
.xword 0 | ||
__os_arm64x_set_x64_information: | ||
.xword 0 | ||
__os_arm64x_check_icall_cfg: | ||
.xword 0 | ||
__os_arm64x_dispatch_fptr: | ||
.xword 0 | ||
__os_arm64x_helper0: | ||
.xword 0 | ||
__os_arm64x_helper1: | ||
.xword 0 | ||
__os_arm64x_helper2: | ||
.xword 0 | ||
__os_arm64x_helper3: | ||
.xword 0 | ||
__os_arm64x_helper4: | ||
.xword 0 | ||
__os_arm64x_helper5: | ||
.xword 0 | ||
__os_arm64x_helper6: | ||
.xword 0 | ||
__os_arm64x_helper7: | ||
.xword 0 | ||
__os_arm64x_helper8: | ||
.xword 0 | ||
|
||
.data | ||
.globl __chpe_metadata | ||
.p2align 3, 0 | ||
__chpe_metadata: | ||
.word 1 | ||
.rva code_map | ||
.word code_map_count | ||
.word 0 // __x64_code_ranges_to_entry_points | ||
.word 0 //__arm64x_redirection_metadata | ||
.rva __os_arm64x_dispatch_call_no_redirect | ||
.rva __os_arm64x_dispatch_ret | ||
.rva __os_arm64x_check_call | ||
.rva __os_arm64x_check_icall | ||
.rva __os_arm64x_check_icall_cfg | ||
.word 0 // __arm64x_native_entrypoint | ||
.word 0 // __hybrid_auxiliary_iat | ||
.word 0 // __x64_code_ranges_to_entry_points_count | ||
.word 0 // __arm64x_redirection_metadata_count | ||
.rva __os_arm64x_get_x64_information | ||
.rva __os_arm64x_set_x64_information | ||
.word 0 // __arm64x_extra_rfe_table | ||
.word 0 // __arm64x_extra_rfe_table_size | ||
.rva __os_arm64x_dispatch_fptr | ||
.word 0 // __hybrid_auxiliary_iat_copy | ||
.rva __os_arm64x_helper0 | ||
.rva __os_arm64x_helper1 | ||
.rva __os_arm64x_helper2 | ||
.rva __os_arm64x_helper3 | ||
.rva __os_arm64x_helper4 | ||
.rva __os_arm64x_helper5 | ||
.rva __os_arm64x_helper6 | ||
.rva __os_arm64x_helper7 | ||
.rva __os_arm64x_helper8 | ||
|
||
__security_cookie: | ||
.xword 0 |
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.
Unnecessary
else
.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.
I wrote it that way to be consistent with other similar functions in that file (just above the new one). Should such change be a separated NFC MR keeping them consistent?
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.
Sure, doing them as a follow up should be okay.