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

c18n: Support for wrapping function pointers in trampolines #2301

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

dpgao
Copy link
Contributor

@dpgao dpgao commented Jan 26, 2025

This PR depends on #2300 and so duplicates its commits, but the real content starts from c18n: Lazy trampolines.

Commit kernel: [WIP] Support for R_{AARCH64,MORELLO}_FUNC_RELATIVE relocations needs further work because it is unclear what relocbase should be used during self-relocation of the kernel.

Comment on lines 770 to 774
switch (ELF_R_TYPE(rela->r_info)) {
case R_AARCH64_RELATIVE:
case R_AARCH64_FUNC_RELATIVE:
/* XXX Dapeng: Which base to use here? */
break;
Copy link
Member

Choose a reason for hiding this comment

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

As discussed on Zoom: the kernel is position-dependent so should not have any R_AARCH64_RELATIVE relocations, but we should check that LLD definitely won't emit them for a ptraddr_t global in a purecap kernel. If it does emit them for whatever reason, relocbase is 0 for the kernel (due to being linked at an absolute address), and that is what the 0 in the call to build_cap_from_fragment is for, so these relocations would be a no-op anyway. The only reason R_MORELLO_RELATIVE is needed (and, soon, FUNC_RELATIVE) is because of the need to derive valid caps at run time for their tags.

@dpgao dpgao force-pushed the c18n-fptr branch 6 times, most recently from 7267bc6 to 114d0ed Compare February 2, 2025 22:56
@gvnn3 gvnn3 requested review from markjdb and bsdjhb February 5, 2025 13:52
dpgao added 5 commits February 5, 2025 18:31
Sometimes we need to create a trampoline based on incomplete
information. For example, if we require all function pointers to be
wrapped in trampolines and have the following code:

	static void foo() {};
	ptraddr_t p = (ptraddr_t)&foo;

The runtime linker needs to create a trampoline using an address
generated from an integer relative relocation. We create a half-baked
trampoline that has a canonical address but that does not have a full
capability as its target. Hence this trampoline cannot be called.

If in the future, some other piece of code does require a callable
trampoline for foo (e.g. through a CAPINIT relocation or simply dlsym),
this half-baked trampoline is retrieved and mutated to its final form.
Setting this flag causes all function pointers to be wrapped in
trampolines. Binaries MUST be compiled with -cheri-codeptr-relocs for
this to work properly.

This flag is only available as a transition mechanism. It will become
the default in the future and the flag will then be removed.
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.

2 participants