On 2020-04-06, Kevin O'Connor wrote:
On Wed, Apr 01, 2020 at 10:29:13AM -0700, Fangrui Song wrote:
Accepting ET_EXEC as an input file is an extremely rare GNU ld feature
that lld does not intend to support, because this is error-prone.
See Linux kernel commit 90ceddcb495008ac8ba7a3dce297841efcd7d584 for
another use of the dd trick.
--
Changes v1 -> v2
* Add status=none to the dd command line. This suppresses dd's stderr output.
* Move dd command to a separate command
Signed-off-by: Fangrui Song <mask...@google.com>
---
Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Makefile b/Makefile
index 5f7d537..118dec0 100644
--- a/Makefile
+++ b/Makefile
@@ -177,10 +177,14 @@ $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds
$(OUT)code32flat.o $(OUT)code
$(OUT)rom16.o: $(OUT)code16.o $(OUT)romlayout16.lds
@echo " Linking $@"
$(Q)$(LD) -T $(OUT)romlayout16.lds $< -o $@
+ # Change e_type to ET_REL so that it can be used to link rom.o.
+ # Unlike GNU ld, lld does not allow an ET_EXEC input.
+ printf '\1' | dd of=$@ conv=notrunc bs=1 seek=16 status=none
$(OUT)rom32seg.o: $(OUT)code32seg.o $(OUT)romlayout32seg.lds
@echo " Linking $@"
$(Q)$(LD) -T $(OUT)romlayout32seg.lds $< -o $@
+ printf '\1' | dd of=$@ conv=notrunc bs=1 seek=16 status=none
My high-level feedback is that the above is very fragile. I'd be
reluctant to adopt that hack. What is the underlying issue that needs
to be addressed?
-Kevin
lld does not take ET_EXEC as input. This is a deliberate choice.
GNU gold does not accept ET_EXEC as well:
% gold a
gold: error: a: unsupported ELF file type 2
1 ET_REL represents object files (.o)
2 ET_EXEC represents position-dependent executables.
3 ET_DYN represents shared objects (.so) (or PIE; for linking purposes, PIE
cannot be accepted)
4 ET_CORE represents core files. For linking purposes, they cannot be accepted.
I don't know how GNU ld ends up accepting ET_EXEC. I am not even sure it
is an intentional decision. A lot of sections will not be meaningful
to the linker and accidentally mixing an ET_EXEC can likely lead to
hard-to-debug linking issues.
I made a similar change to Linux recently.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
$(OUT)rom.o: $(OUT)rom16.strip.o $(OUT)rom32seg.strip.o $(OUT)code32flat.o
$(OUT)romlayout32flat.lds
@echo " Linking $@"
--
2.26.0.rc2.310.g2932bb562d-goog
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-le...@seabios.org
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-le...@seabios.org