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

linker: Allow calling into unimplemented forward function declarations #544

Merged
merged 3 commits into from
Jan 21, 2022

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Jan 20, 2022

After #508, the linker became more restrictive regarding jumps to symbols that don't appear in the same section, as these usually mean a function in another section is called. One notable exception to this rule is forward function declarations that are left unimplemented.

This patch adds the possibility for the caller to provide an implementation for these symbols after the CollectionSpec has been emitted. Instead, throw an error when the ProgramSpec is instantiated into a Program.

Fixes #531

@arthurfabre Please check if this works as expected for your production code.

Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok to me, not sure how the changes you made make it work though :D

linker.go Outdated Show resolved Hide resolved
@ti-mo
Copy link
Collaborator Author

ti-mo commented Jan 21, 2022

not sure how the changes you made make it work though

references is only really used in flatten(), where it's iterated over, not looked up in. This results in the fwd function not being concatenated to the full insn stream (since there is no ProgramSpec and thus no body), so fixupJumpsAndCalls will find a jump without a target at load time.

ti-mo and others added 3 commits January 21, 2022 13:34
Adding errUnsatisfiedProgram in a follow-up, we need to tell the two apart.

Signed-off-by: Timo Beckers <timo@isovalent.com>
…alls

Allow the caller to make forward function declarations in C and provide the
final implementation after the CollectionSpec has been loaded.

Fix a papercut where NewProgram panics when called with a nil spec.

Signed-off-by: Timo Beckers <timo@isovalent.com>
This test makes sure the linker allows calls into missing symbols
so that they can be provided by the caller after the CollectionSpec
has been emitted.
@ti-mo ti-mo merged commit 0c343b5 into cilium:master Jan 21, 2022
@ti-mo ti-mo deleted the tb/linker-fwd-decl branch January 21, 2022 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function calls can't be linked after loading an ELF
3 participants