* [PATCH 1/5] kbuild: remove unneeded -nostdlib flag
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
@ 2021-11-17 3:49 ` Masahiro Yamada
2021-11-17 3:49 ` [PATCH 2/5] x86: remove x86-specific cmd_barebox__ Masahiro Yamada
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2021-11-17 3:49 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
The -nostdlib option requests the compiler to not use the standard
system startup files or libraries when linking.
arch/kvm/Makefile adds it to KBUILD_CFLAGS/AFLAGS, but it does not make
sense because those are unrelated to linking.
arch/{mips,riscv,x86}/Makefile passes it to the linker, but it is not
sensible either. As noted above, adding -nostdlib makes sense only
when $(CC) is used as a linker driver, but $(LD) is directly used for
linking barebox. (ld.bfd/ld.lld recognizes the -nostdlib flag, but its
behavior is obscure, and unneeded here.)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/kvx/Makefile | 2 +-
arch/mips/Makefile | 2 --
arch/riscv/Makefile | 1 -
arch/x86/Makefile | 2 +-
4 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/kvx/Makefile b/arch/kvx/Makefile
index 13c4e2431..f29eeef92 100644
--- a/arch/kvx/Makefile
+++ b/arch/kvx/Makefile
@@ -8,7 +8,7 @@ ifeq ($(CROSS_COMPILE),)
CROSS_COMPILE := kvx-elf-
endif
-DEFAULT_CFLAGS := -nostdlib -fno-builtin -fstrict-align -g
+DEFAULT_CFLAGS := -fno-builtin -fstrict-align -g
DEFAULT_CFLAGS += -DTEXT_BASE=$(CONFIG_TEXT_BASE)
LIBGCC_PATH = $(dir $(shell $(CC) $(KBUILD_CFLAGS) --print-libgcc-file-name))
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 4eb6ba772..786695194 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -72,8 +72,6 @@ KBUILD_BINARY := barebox.bin
KBUILD_TARGET := barebox.bin
endif
-LDFLAGS_barebox += -nostdlib
-
machine-$(CONFIG_MACH_MIPS_MALTA) := malta
machine-$(CONFIG_MACH_MIPS_AR231X) := ar231x
machine-$(CONFIG_MACH_MIPS_ATH79) := ath79
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 0b1278936..23ea6178a 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -17,7 +17,6 @@ PBL_CPPFLAGS += $(riscv-cflags-y)
LDFLAGS_pbl += $(riscv-ldflags-y)
cflags-y += $(riscv-cflags-y)
-LDFLAGS_barebox += -nostdlib
LDFLAGS_barebox += $(riscv-ldflags-y)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index fd871ca21..9fc64cc04 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -54,7 +54,7 @@ lds-$(CONFIG_X86_64) := arch/x86/mach-efi/elf_x86_64_efi.lds
cmd_barebox__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_barebox) -o $@ \
-T $(lds-y) \
- -shared -Bsymbolic -nostdlib -znocombreloc \
+ -shared -Bsymbolic -znocombreloc \
--whole-archive $(BAREBOX_OBJS) \
--no-whole-archive \
$(filter-out $(BAREBOX_LDS) $(BAREBOX_OBJS) FORCE ,$^)
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/5] x86: remove x86-specific cmd_barebox__
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
2021-11-17 3:49 ` [PATCH 1/5] kbuild: remove unneeded -nostdlib flag Masahiro Yamada
@ 2021-11-17 3:49 ` Masahiro Yamada
2021-11-17 3:49 ` [PATCH 3/5] x86: stop copying unneeded sections to barebox.efi Masahiro Yamada
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2021-11-17 3:49 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
The difference from cmd_barebox__ in the top Makefile is:
-shared -Bsymbolic -znocombreloc
Put the flags to LDFLAGS_barebox, and remove the x86-specific
cmd_barebox__.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/x86/Makefile | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 9fc64cc04..c73842cf8 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -28,7 +28,9 @@ endif
ifndef CONFIG_MODULES
# Add cleanup flags
-ifneq ($(CONFIG_X86_EFI),y)
+ifeq ($(CONFIG_X86_EFI),y)
+LDFLAGS_barebox += -shared -Bsymbolic -znocombreloc
+else
KBUILD_CPPFLAGS += -fdata-sections -ffunction-sections
LDFLAGS_barebox += -static --gc-sections
endif
@@ -52,13 +54,6 @@ common-y += arch/x86/lib/
lds-$(CONFIG_X86_32) := arch/x86/mach-efi/elf_ia32_efi.lds
lds-$(CONFIG_X86_64) := arch/x86/mach-efi/elf_x86_64_efi.lds
-cmd_barebox__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_barebox) -o $@ \
- -T $(lds-y) \
- -shared -Bsymbolic -znocombreloc \
- --whole-archive $(BAREBOX_OBJS) \
- --no-whole-archive \
- $(filter-out $(BAREBOX_LDS) $(BAREBOX_OBJS) FORCE ,$^)
-
quiet_cmd_efi_image = EFI-IMG $@
cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc -j __barebox_initcalls \
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/5] x86: stop copying unneeded sections to barebox.efi
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
2021-11-17 3:49 ` [PATCH 1/5] kbuild: remove unneeded -nostdlib flag Masahiro Yamada
2021-11-17 3:49 ` [PATCH 2/5] x86: remove x86-specific cmd_barebox__ Masahiro Yamada
@ 2021-11-17 3:49 ` Masahiro Yamada
2021-11-17 3:49 ` [PATCH 4/5] x86: reuse cmd_objcopy to generate barebox.efi Masahiro Yamada
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2021-11-17 3:49 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
Stop copying the following sections:
__barebox_initcalls
__barebox_exitcalls
__barebox_cmd
.barebox_magic
Such sections do not exist.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/x86/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index c73842cf8..5623b2cea 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -56,8 +56,7 @@ lds-$(CONFIG_X86_64) := arch/x86/mach-efi/elf_x86_64_efi.lds
quiet_cmd_efi_image = EFI-IMG $@
cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
- -j .dynsym -j .rel -j .rela -j .reloc -j __barebox_initcalls \
- -j __barebox_exitcalls -j __barebox_cmd -j .barebox_magicvar \
+ -j .dynsym -j .rel -j .rela -j .reloc \
-j .bbenv.* -j .bblogo.* --target=$(TARGET) $< $@
KBUILD_BINARY := barebox
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/5] x86: reuse cmd_objcopy to generate barebox.efi
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
` (2 preceding siblings ...)
2021-11-17 3:49 ` [PATCH 3/5] x86: stop copying unneeded sections to barebox.efi Masahiro Yamada
@ 2021-11-17 3:49 ` Masahiro Yamada
2021-11-17 3:49 ` [PATCH 5/5] x86_64: do not pass the EFI image handle or system table to relocation Masahiro Yamada
2021-11-17 7:42 ` [PATCH 0/5] x86: misc cleanups Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2021-11-17 3:49 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
The objcopy rule is defined in scripts/Makefile.lib
Reuse it.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/x86/Makefile | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 5623b2cea..53cbd5088 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -54,17 +54,16 @@ common-y += arch/x86/lib/
lds-$(CONFIG_X86_32) := arch/x86/mach-efi/elf_ia32_efi.lds
lds-$(CONFIG_X86_64) := arch/x86/mach-efi/elf_x86_64_efi.lds
-quiet_cmd_efi_image = EFI-IMG $@
- cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
- -j .dynsym -j .rel -j .rela -j .reloc \
- -j .bbenv.* -j .bblogo.* --target=$(TARGET) $< $@
-
KBUILD_BINARY := barebox
KBUILD_LDFLAGS := --no-undefined
+OBJCOPYFLAGS_barebox.efi = \
+ -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela \
+ -j .reloc -j .bbenv.* -j .bblogo.* --target=$(TARGET)
+
barebox.efi: $(KBUILD_BINARY) FORCE
- $(call if_changed,efi_image)
+ $(call if_changed,objcopy)
KBUILD_IMAGE := barebox.efi
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/5] x86_64: do not pass the EFI image handle or system table to relocation
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
` (3 preceding siblings ...)
2021-11-17 3:49 ` [PATCH 4/5] x86: reuse cmd_objcopy to generate barebox.efi Masahiro Yamada
@ 2021-11-17 3:49 ` Masahiro Yamada
2021-11-17 7:42 ` [PATCH 0/5] x86: misc cleanups Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2021-11-17 3:49 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
The _reloc() function in reloc_x86_64.c is passed with the EFI image
handle and system table, but they are unrelated to the relocation.
In fact, they are not used at all.
Remove them and clean up the assembler code as well.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/x86/mach-efi/crt0-efi-x86_64.S | 6 +-----
arch/x86/mach-efi/reloc_x86_64.c | 4 ++--
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/arch/x86/mach-efi/crt0-efi-x86_64.S b/arch/x86/mach-efi/crt0-efi-x86_64.S
index aa03106e9..d23c1fb2d 100644
--- a/arch/x86/mach-efi/crt0-efi-x86_64.S
+++ b/arch/x86/mach-efi/crt0-efi-x86_64.S
@@ -47,14 +47,10 @@ _start:
lea image_base(%rip), %rdi
lea _DYNAMIC(%rip), %rsi
- popq %rcx
- popq %rdx
- pushq %rcx
- pushq %rdx
call _relocate
- popq %rdi
popq %rsi
+ popq %rdi
call efi_main
addq $8, %rsp
diff --git a/arch/x86/mach-efi/reloc_x86_64.c b/arch/x86/mach-efi/reloc_x86_64.c
index e83bacb30..f015ae047 100644
--- a/arch/x86/mach-efi/reloc_x86_64.c
+++ b/arch/x86/mach-efi/reloc_x86_64.c
@@ -41,9 +41,9 @@
#include <elf.h>
-asmlinkage efi_status_t _relocate (long, Elf64_Dyn *, efi_handle_t, efi_system_table_t *);
+asmlinkage efi_status_t _relocate(long, Elf64_Dyn *);
-efi_status_t _relocate (long ldbase, Elf64_Dyn *dyn, efi_handle_t image, efi_system_table_t *systab)
+efi_status_t _relocate(long ldbase, Elf64_Dyn *dyn)
{
long relsz = 0, relent = 0;
Elf64_Rel *rel = 0;
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] x86: misc cleanups
2021-11-17 3:49 [PATCH 0/5] x86: misc cleanups Masahiro Yamada
` (4 preceding siblings ...)
2021-11-17 3:49 ` [PATCH 5/5] x86_64: do not pass the EFI image handle or system table to relocation Masahiro Yamada
@ 2021-11-17 7:42 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2021-11-17 7:42 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: barebox
On Wed, Nov 17, 2021 at 12:49:13PM +0900, Masahiro Yamada wrote:
>
>
>
> Masahiro Yamada (5):
> kbuild: remove unneeded -nostdlib flag
> x86: remove x86-specific cmd_barebox__
> x86: stop copying unneeded sections to barebox.efi
> x86: reuse cmd_objcopy to generate barebox.efi
> x86_64: do not pass the EFI image handle or system table to relocation
Applied all, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread