-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[llvm-objcopy] Always update indirectsymoff in MachO #117726
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
Conversation
@llvm/pr-subscribers-llvm-binary-utilities Author: Richard Dzenis (RIscRIpt) ChangesLet's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore. Then according to previous code we would not update indirectsymoff field. This would lead to Codesign has a strict check that size of MachO file must be equal to
If this is not satisfied codesign reports the following error
Full diff: https://github.com/llvm/llvm-project/pull/117726.diff 1 Files Affected:
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index a3d4ba3a94f7ac..551ff4501a66fb 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -361,11 +361,10 @@ Error MachOLayoutBuilder::layoutTail(uint64_t Offset) {
return createStringError(llvm::errc::not_supported,
"shared library is not yet supported");
- if (!O.IndirectSymTable.Symbols.empty()) {
- MLC.dysymtab_command_data.indirectsymoff = StartOfIndirectSymbols;
- MLC.dysymtab_command_data.nindirectsyms =
- O.IndirectSymTable.Symbols.size();
- }
+ MLC.dysymtab_command_data.nindirectsyms =
+ O.IndirectSymTable.Symbols.size();
+ MLC.dysymtab_command_data.indirectsymoff =
+ O.IndirectSymTable.Symbols.empty() ? 0 : StartOfIndirectSymbols;
updateDySymTab(MLC);
break;
|
Thanks for the fix. Please add/update a test case to cover this behaviour. As this is fixing an issue, please add "Fixes: #XXXXXX" (where XXXXXX is the issue number) to the PR description and remove the reference from the PR title. Please could you add some reviewers who have been involved in modifying the Mach-O code in llvm-objcopy, either officially as reviewers, or by pinging them in the comments, depending on whether you have commit access or not. |
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.
Please add a test case for a binary that has 0 and >0 indirect symbols.
I find it difficult generating a MachO reliably so that all the nuances are preserved to observe the desired effect. I try to investigate how to craft such MachO if reviewers think I should add a regression test.
As far as I can see @nuta who was the author of this file was not contributing to llvm-project lately (as per |
Take a look at obj2yaml - that will allow you to generate the code once and then trim down the MachO binary to the shape that we need for the test.
Yes, please add the regression tests for this. |
Thanks for the fix, i second @compnerd's suggestions |
I didn't know
I've added a very small test, please see if it's enough. |
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.
Do you think it would be possible to add a test case where there are indirect symbols (or is there an existing test case for that?)
There are some:
Edit: most notably symbol-table.test, where different kinds of symbols are checked, including one indirect symbol. |
llvm/test/tools/llvm-objcopy/MachO/symtbl-zero-indirectsymoff.test
Outdated
Show resolved
Hide resolved
@alexander-shaposhnikov - any additional feedback? |
Many thanks for the review! If there would be no additional feedback, I'll merge it in a couple of days, when I have more time to be online in case of test failures in main. |
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.
LG
Let's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore. Then according to previous code we would not update indirectsymoff field. This would lead to `MachOWriter::totalSize()` report size that is larger than the new MachO. As a result we would get MachO that has zero bytes past contents of the very last load command. Codesign has a strict check that size of MachO file must be equal to lastLoadCommand.offset + lastLoadCommand.size If this is not satisfied codesign reports the following error main executable failed strict validation Fixes llvm#117723
2addd7d
to
a4a49ad
Compare
Let's say we've run llvm-strip over some MachO. The resulting MachO became smaller and there are no indirect symbols anymore.
Then according to previous code we would not update indirectsymoff field. This would lead to
MachOWriter::totalSize()
report size that is larger than the new MachO. As a result we would get MachO that has zero bytes past contents of the very last load command.Codesign has a strict check that size of MachO file must be equal to
If this is not satisfied codesign reports the following error
Fixes #117723