Thread (8 messages) 8 messages, 4 authors, 2024-09-03

Re: [PATCH] kbuild: use objcopy to generate asm-offsets

From: Vegard Nossum <hidden>
Date: 2024-08-28 10:07:59
Also in: bpf, kvm, kvmarm, linux-kbuild, linux-omap, linux-um, lkml, llvm

On 28/08/2024 10:36, Vegard Nossum wrote:
In order to give assembly code access to C structs without having to
hardcore member offsets, the kernel compiles a C source file listing all
the structs and offsets that are needed in assembly code. Using some
C preprocessor trickery and a sed script, the compiled assembly code is
turned back into C preprocessor code that in turn can be used by the
asssembly code.

This sed script is very hard to read and understand.

Remove the sed script and compile the C source listing structs and
offsets to an object file (instead of assembly code) that embeds C source
directly. Then extract the C source using objcopy.

The resulting code is more readable, less fragile, and sligthly shorter.

Note to reviewers: The 'objcopy ... /dev/stdout | cat' bit is needed to
force the correct ordering of the objcopy lines vs. the surrounding echo
commands; without it, objcopy will open /dev/stdout (which refers to a
temporary file created by kbuild) and reset the file offset to 0. In
other words, the pipe ensures that objcopy doesn't overwrite the lines
that already exist in /dev/stdout.
Turns out LLVM's objcopy doesn't support writing to /dev/stdout, so we
might have to use a temporary file. I'll look into it and send a v2.


Vegard
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help