-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
modlib: preprocess gnu-elf.ld for executable ELF #15444
base: master
Are you sure you want to change the base?
Conversation
[Experimental Bot, please feedback here] Yes, this PR appears to meet the basic NuttX requirements, although it could be more thorough. While it addresses the key points, it lacks specific details in several areas which would make review easier. Here's a breakdown: Strengths:
Weaknesses:
Recommendation: The PR author should add the missing details to strengthen it. Specifically:
|
arch/arm/src/common/Toolchain.defs
Outdated
endif | ||
|
||
LDELFFLAGS += -e main -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld) | ||
ifneq ($(CONFIG_BINFMT_ELF_EXECUTABLE),y) | ||
LDELFFLAGS += -e main -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we share the same gnu-elf.ld for relacation and exeutable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the gnu-elf.ld
in boards/
folder contains target specific .text
address, which is specific to target virtual space design now. If later NuttX kernel build has a unified virtual space design (e.g. kernel at highmem, userspace in lowmem), I believe one userspace gnu-elf.ld
will be enough. So maybe we should track unified userspace memory layout separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why not unify the layout now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the linker script board specific data anyway, why must we change (or for that matter, have) anything in the common modlib folder, I don't understand ?
I presume the linker file in the modlib folder is there as an example, not intended for production use in any case.
I question the motivation to have this change at all in upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elf file linker script is different from board linker script, since the layout should be general for all board like how Linux done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, the Linux toolchain has a generic linker script, so maybe this change is not as bad as I initially thought. I personally have the gnu-elf.ld file in the board folder for my projects because I still think it is board specific (for now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why not unify the layout now?
Us having a unified virtual address spacing (e.g. user in lowmem, kernel in himem) for now is impossible, as we do not have a good mechanism to move memory mapped devices into the kernel virtual memory area (like fdt and vmap). We have the pieces in place but not a single platform implements this AFAIK ?
This is why I for example configure MPFS the other way around; userspace starts from 0xc000_0000 and kernel resides in the lower part.
I guess this patch does not break this functionality, so I'm fine with it.
Seems that CI is blocked by issue similar to #15441? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a Documentation/ at qemu page showing a usage example
This allows the header file to be useful from non-C sources such as assembly code or linker scripts. Signed-off-by: Yanfeng Liu <[email protected]>
This generates gnu-elf.ld via preprocessing of gnu-elf.ld.in so that to reduce board specific app linker scripts in kernel mode when BINFMT_ELF_EXECUTABLE is enabled. Signed-off-by: Yanfeng Liu <[email protected]>
This avoids using `-r` option when linking executable programs. Signed-off-by: Yanfeng Liu <[email protected]>
This allows using BINFMT_ELF_EXECUTABLE for qemu-armv7a target. Signed-off-by: Yanfeng Liu <[email protected]>
@acassis, the usage is rather simple: just enable BINFMT_ELF_EXECUTABLE config for a kernel build. Actually this isn't new or specific to QEMU, I used it before for k230 devices, all canmv230 kernel mode have it enable by default, see pull/11513 for the old story. |
Summary
This allows apps for kernel mode NuttX (e.g. on arm/qemu-armv7a) can be built as executable type ELF files. Benefits of executable programs are smaller in size and easier GDB debugging.
Initial scope was only for qemu-armv7a but it used an almost duplicated
gnu-elf.ld
which differs only at.text
and.data
addresses from thegnu-elf.ld
in modlib.To avoid such duplications, a preprocessed
gnu-elf.ld
in modlib is added so that to adapt to target config. This requires minor tweaks foraddrenv.h
so that some macros can be included ingnu-elf.ld.in
.Impacts
Hardware: qemu-armv7a or using kernel build.
Testing
qemu-armv7a:knsh
,bl602evb:elf
.