-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
__data_end may not correctly represent text start position when using CFG_WITH_PAGER #1071
Comments
Yes, this is a bug. |
In #1044 there's a patch (core: arm: kern.ld.S: consistent 8 bytes alignment) that may fix this. |
I think we can solve this problem by padding the tee-pager.bin to the size of __data_end: This is the original linker script to produce the tee-pager.bin:
This is the fixed one, adding the --pad-to line in objcopy:
and __data_end is obtained by NM the ELF, as usual
|
And the real cause is this, .ctors/.dtor sections are 8 bytes aligned, and they are empty sections; so if previous section does not end at 8 bytes boundary, it moves the current address forward, while it does not fill any content because it is empty. The OBJDUMP utility only dumps content to the end of previous non-empty sections. Adding --pad-to can solve this problem:
|
I like this approach. Can you make a pull request based on this? |
Closing this issue since the proposed change has been merged. Feel free to re-open it if needed. |
When configured with pager, non-paged part is appended at end of data section and is moved to correct position during start:
However, sometimes the __data_end is not the position. The image is built as:
[pager code, rodate and data] + [Init code + others]
the linker script puts all data sections together and after that is __data_end. However, if the length of the last few data sections are 0x0, and if some of the data sections are 4 bytes aligned, it moves the __data_end to 4 bytes boundary, but the actual length of the data section (i.e., the position where to concatenate the text section) does not move forward.
An example is shown below:
Here the end of the data is at 0x4e0111ec, while the next .ctors advance the end to 0x4e0111f0 due to alignment requirement. The resultant __data_end is also 0x4e0111f0. Unfortunately, when building the tee.bin, the objdump does not care about the empty data sections so the actual binary end at 0x4e0111ec, from which the text are appended, see hexdump of tee.bin:
the text
b048 b083
should begin at 0x1120c (0x111f0+0x1C OPTEE header), but it begins at 0x11208.The text was updated successfully, but these errors were encountered: