-
Notifications
You must be signed in to change notification settings - Fork 8.2k
LLEXT: Relocatable fixes #72479
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
LLEXT: Relocatable fixes #72479
Conversation
pillo79
left a comment
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.
Thanks for the debug, LGTM, just one small refactor request.
subsys/llext/llext.c
Outdated
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.
This code is duplicated, can you please refactor so the calculation and log is done once outside the if?
Also, note the commit that introduces it has a spelling issue in the commit title.
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.
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.
The only difference in the address calculation (arguably the most important line in the whole function!) is just the name of one argument; in the log, there is a section name that could be calculated for the other case.
I really see no point in having 2 code paths that do the same logical thing in different ways.
b34cc88 to
837b504
Compare
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.
Minor typo in commit s/stanrads/standard
changes look good to me
|
Sorry I maybe wasn't clear enough where I saw the typo, the commit message for 2235022 has github doesn't necessarily let me comment on a commit message, boooo |
teburd
left a comment
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.
Minor nits still, but the change looks ok to me otherwise
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 love the idea of being able to respect the ELF-provided addresses, but IMO we really need a test case for this new feature in Zephyr. I don't want to have to guess if any of the patches I submit are breaking SOF... (or even worse, hear screaming coming that way 😅)
subsys/llext/llext.c
Outdated
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 think this should be:
| sym_tab->syms[j].addr = (uint8_t *)sym.st_value + | |
| (ldr->hdr.e_type == ET_REL ? section_addr : 0); | |
| sym_tab->syms[j].addr = (uint8_t *)section_addr | |
| + sym.st_value; |
because in the "pre-located" case the symbols'VMA should not be modified, so the calculation is the same regardless of dynamic or static linking.
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.
@pillo79 no, the difference between ET_REL (relocatable object) and ET_DYN (shared object) remains. In the relocatable case that calculation is correct:
[ 113.934401] <inf> llext: llext_copy_symbols: type: 1 sym volume_init: 0x1e8c section 0xa068a000
[ 113.934410] <inf> llext: llext_copy_symbols: type: 1 sym volume_func_count: 0x24 section 0xa068e000
[ 113.934420] <inf> llext: llext_copy_symbols: type: 1 sym volume_reset_state: 0xf50 section 0xa068a000
but in the shared case it's this:
[ 150.092295] <inf> llext: llext_copy_symbols: type: 3 sym volume_init: 0xa068ba5c section 0xa068a000
[ 150.092306] <inf> llext: llext_copy_symbols: type: 3 sym volume_func_count: 0xa068d0b0 section 0xa068d000
[ 150.092318] <inf> llext: llext_copy_symbols: type: 3 sym volume_reset_state: 0xa068b510 section 0xa068a000
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.
You're right, that is indeed why it's subtracted in the else case!
include/zephyr/llext/llext.h
Outdated
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 think something like "Use the virtual symbol addresses from the ELF instead of the run-time ones" might be clearer here.
@pillo79 testing is good... We could add a test where an LLEXT is built for a fixed address, but for which one? You'd probably need to modify a linker script to assign a fixed address range for that extension? And that would be testing / twister-specific, whereas now standard scripts, e.g. soc/cdns/dc233c/include/xtensa-dc233c.ld are used... Any ideas? |
You could use the SOF strategy and add a custom re-link step that only fixes an integer variable to |
@pillo79 not sure I understand. We need to build an LLEXT with some predefined address, similar to how we do for SOF by using
So, not quite trivial unless there's a simpler way |
When building partially linked / relocatable objects no ELF segments are created and it becomes more difficult to predict which sections the compiler will build and use. In this case a .data.rel.local section is created by the compiler and it is needed to link .rodata strings in a twister test. We can handle arbitrary sections at run- time if .peek() is supported. If it isn't we need to allocate and copy the section. For now we simply error out in such cases. Fixing that would represent a larger change and can be done incrementally. This also fixes the relocation calculation to point to the correct symbol address instead of the memory location, where it's currently residing, because that can be a temporary buffer as is the case with SOF. Signed-off-by: Guennadi Liakhovetski <[email protected]>
Use an existing variable instead of re-calculating and fix swapped space and a paranthesis. Signed-off-by: Guennadi Liakhovetski <[email protected]>
Zero offset in a relocation entry is valid, shouldn't ignore it. Signed-off-by: Guennadi Liakhovetski <[email protected]>
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.
LGTM, will merge the test from #73479 after this.
two fixes for relocatable LLEXT objects. This should fix errors in #72383