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

Add LoongArch support for kpatch #1424

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

georgejguo
Copy link
Contributor

No description provided.

Add section alt_instr check support for LoongArch.

Signed-off-by: George Guo <[email protected]>
Add initial support for LoongArch.

Signed-off-by: George Guo <[email protected]>
…ries

Generate 2 NOPs right at the beginning of each function with
-fpatchable-function-entry=2 in LoongArch. So here create section
__patchable_function_entries and check this situation.

Co-developed-by: zhanghongchen <[email protected]>
Signed-off-by: George Guo <[email protected]>
Here fix error like: "tcp.o: symbol changed sections: .LBB7266.
create-diff-object: unreconcilable difference".
Due to LoongArch GCC generating local labels such as .LBB7266,
it is difficult to compare the modified sections in the
corresponding object files of the two files before and after
the patch, so change them with sections symbols in rela section,
and delete them in other sections.

Co-developed-by: zhanghongchen <[email protected]>
Signed-off-by: George Guo <[email protected]>
Take tcp.o as an example. An ld error occurs as follows:
"ld: __patchable_function_entries has both ordered and
unordered sections" when linking patch-hook.o and output.o.

The link error is triggered by running the command:
"ld -r --unique=.parainstructions --unique=.altinstructions -o
patch/tmp_output.o output/net/ipv4/tcp.o".

With -fpatchable-function-entry, LoongArch GCC sets WAL flags
for section __patchable_function_entries in object file
(which includes patch-hook.o) by default.
Meanwhile, Kpatch sets A flags for output.o in create_section_pair().
To resolve the ld error, we set sh_flags = WAL.

Signed-off-by: George Guo <[email protected]>
Since kpatch now supports LoongArch basically, enable the build.

Signed-off-by: George Guo <[email protected]>
Omit patchable sections compare processing, as we will rebuild it.

Signed-off-by: George Guo <[email protected]>
Added conditional compilation to prevent 'R_LARCH_64' and 'EM_LOONGARCH'
from being referenced on x86 and other non-LoongArch architectures. This
ensures the code works across different architectures without errors.

Signed-off-by: George Guo <[email protected]>
@joe-lawrence
Copy link
Contributor

Thanks for opening the PR, @georgejguo . The plan is to first merge PR #1415 as the patchable_function_entries section support is not limited to a single arch. Once that code is in place, the arm64 support PR shrinks drastically. I would think a similar simplification for loongarch would be true as well.

@georgejguo
Copy link
Contributor Author

georgejguo commented Nov 11, 2024

Okey, I have seen PR #1415, I'm waiting for it to be merged.

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