Skip to content
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

kernel system call handlers missing due to -Wl,--no-whole-archive #5184

Closed
andrewboie opened this issue Nov 28, 2017 · 5 comments
Closed

kernel system call handlers missing due to -Wl,--no-whole-archive #5184

andrewboie opened this issue Nov 28, 2017 · 5 comments
Assignees
Labels
area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: high High impact/importance bug
Milestone

Comments

@andrewboie
Copy link
Contributor

Discovered by @agross-linaro, who was getting "unimplemented system call" errors on ARM for k_thread_abort().

ARM has a custom implementation of k_thread_abort under arch/arm. This has the effect of compiling out everything in kernel/thread_abort.c except the handler function.
For some strange reason, if --no-whole-archive is enabled, the linker decides to prefer the weak handler for k_thread_abort() in syscall_dispatch.c.

@andrewboie andrewboie self-assigned this Nov 28, 2017
@andrewboie andrewboie added area: Memory Protection bug The issue is a bug, or the PR is fixing a bug labels Nov 28, 2017
@linkmeyer
Copy link

@andrewboie , can you please set the priority?

@galak galak added this to the v1.10.0 milestone Nov 29, 2017
@lpereira lpereira added priority: high High impact/importance bug priority: medium Medium impact/importance bug and removed priority: high High impact/importance bug labels Nov 29, 2017
@lpereira
Copy link
Collaborator

I had originally set this to high because this wouldn't work on ARM, but userland isn't working on ARM yet and won't be at least for 1.11. So moved back to medium.

@galak galak modified the milestones: v1.10.0, v1.11.0 Nov 29, 2017
andrewboie pushed a commit to andrewboie/zephyr that referenced this issue Nov 29, 2017
The core kernel is built with the --no-whole-archive linker option.
For all the individual .o files which make up the kernel, if there
are no external references to symbols within these object files,
everything in the object file is dropped.

This has a subtle interaction with system call handlers. If an object
file has system call handlers inside it, and nothing else in the
object file is referenced, then the linker will prefer the weak
version of the handler in the generated syscall_dispatch.c. The
user will get an "unimplemented system call" error if the associated
system call for that handler is made.

Fix this by making a fake reference to the handler function at the
system call site. The address gets stored inside a special section
"hndlr_ref".  This is enough to prevent the handlers from being
dropped, and the hndlr_ref section is itself dropped from the binary
from gc-sections; these references will not consume space.

Handlers for system calls that are never invoked anywhere will still be
dropped if nothing else in their containing C files is used, which is
a good thing. A future enhancement could be to split out all handlers
into individual object files, such that we can guarantee that any system
call that is not made somewhere in the application will have its handler
dropped. This will need to be extended to driver subsystems as well.
This won't be pretty but will ensure the tightest binary size.

Fixes zephyrproject-rtos#5184.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@andrewboie andrewboie modified the milestones: v1.11.0, v1.10.0 Nov 29, 2017
@andrewboie
Copy link
Contributor Author

This issue affects x86 and needs to go into 1.10

@andrewboie andrewboie added priority: high High impact/importance bug and removed priority: medium Medium impact/importance bug labels Nov 29, 2017
andrewboie pushed a commit that referenced this issue Nov 29, 2017
The core kernel is built with the --no-whole-archive linker option.
For all the individual .o files which make up the kernel, if there
are no external references to symbols within these object files,
everything in the object file is dropped.

This has a subtle interaction with system call handlers. If an object
file has system call handlers inside it, and nothing else in the
object file is referenced, then the linker will prefer the weak
version of the handler in the generated syscall_dispatch.c. The
user will get an "unimplemented system call" error if the associated
system call for that handler is made.

Fix this by making a fake reference to the handler function at the
system call site. The address gets stored inside a special section
"hndlr_ref".  This is enough to prevent the handlers from being
dropped, and the hndlr_ref section is itself dropped from the binary
from gc-sections; these references will not consume space.

Handlers for system calls that are never invoked anywhere will still be
dropped if nothing else in their containing C files is used, which is
a good thing. A future enhancement could be to split out all handlers
into individual object files, such that we can guarantee that any system
call that is not made somewhere in the application will have its handler
dropped. This will need to be extended to driver subsystems as well.
This won't be pretty but will ensure the tightest binary size.

Fixes #5184.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@andrewboie
Copy link
Contributor Author

@AdithyaBaglody discovered that this problem is still happening, my patch didn't completely fix it.
Diving in....

@andrewboie andrewboie reopened this Dec 13, 2017
@andrewboie
Copy link
Contributor Author

@AdithyaBaglody found a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: high High impact/importance bug
Projects
None yet
Development

No branches or pull requests

4 participants