-
Notifications
You must be signed in to change notification settings - Fork 351
cas.o: Improve Block sorting for ELF object ingestion stability #3617
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
base: experimental/cas/main
Are you sure you want to change the base?
cas.o: Improve Block sorting for ELF object ingestion stability #3617
Conversation
|
Now I think about this... If you carefully craft the object file, you can get sorting algorithm to infinite loop. I need to add a maximum depth probably. |
|
Alternative is we can create ELF blocks using its section offset in the file and assign Address 0 to those sections with |
For ELF object files, it can create blocks in the same section that are almost identical except relocations inside the block (e.g. .init_array section). This can cause indeterministic output when converting ELF object files. Fix the problem by recursively looking into relocation targets if needed when sorting blocks/edges.
afc1b27 to
092476a
Compare
|
Please push a standalone commit that moves these to ObjectFormatHelpers that has NFC (don't think it needs review, just push it) and then rebase so it's easy to see what's actually changing here. I'm nervous about making the comparison recursive. What about @lhames's idea to use
|
I want to avoid that as well but there is no other option other than make blocks to have deterministic ordering in Section (using a vector, instead of set). The indeterminism I try to fix here are the blocks for the same section, with no address assigned. |
What about assigning an initial layout in the LinkGraphBuilder? As long as no ELF semantics rely on symbols initially having a null address this seems like it should be safe. |
So I tried an easy patch by using the offset in object file as the address of the block (except those zerofill block gets address 0 since they don't occupy any space in object file) but it turns out it requires more work. I forgot the exact reason but I can easily recreate that and report back. I remember I ditched the idea because the work for building an initial layout in the object file is unnecessary for the use of ELF object in JIT context so I am not sure if we want to pay that cost. |
@lhames This is the cheapest way to give a layout for most of the content in the object file. Does this look ok to you? |
|
I think that should work, but it might be better to assign new addresses to the blocks as a post-processing step on the graph rather than modifying the parser -- that approach should be less sensitive to future changes to the parser. |
It is too late when it turns into the LinkGraph since the offset information is lost and there won't be deterministic ordering for visiting blocks (the problem we try to solve here) so the address assigned will not be deterministic. Let me know if I missed anything. |
|
@swift-ci test |
No, you're right -- doing this in the LinkGraph will be too late for your purposes. I'm back to thinking that the parser is the right place to implement this.
Ok. We should have a talk about determinism for JITLink plugins -- we haven't promised that to clients yet, but maybe we'll want it in the future, in which case this cost will have to be paid anyway. It's also likely to be pretty cheap relative to everything else that JITLink and ORC are doing. |
(BTW, if you've pushed something, maybe you need to rebase, since I still can't easily tell what's changed... but maybe you're not ready for a review yet anyway...)
Or a SetVector. Or, add an BlockID field to
|
For ELF object files, it can create blocks in the same section that are
almost identical except relocations inside the block (e.g. .init_array
section). This can cause indeterministic output when converting ELF
object files. Fix the problem by recursively looking into relocation
targets if needed when sorting blocks/edges.