From e25230e2439f5a8f973a66fce5ee2d2bddf20883 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 17 Nov 2021 12:49:14 +0900 Subject: kbuild: remove unneeded -nostdlib flag 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 Link: https://lore.barebox.org/20211117034918.1226358-2-masahiroy@kernel.org Signed-off-by: Sascha Hauer --- 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 13c4e24319..f29eeef921 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 4eb6ba7721..7866951944 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 0b1278936d..23ea6178a2 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 fd871ca214..9fc64cc047 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 ,$^) -- cgit v1.2.3 From a5c549e29a07f34a3f85f265b6ab56ae3de8eb20 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 17 Nov 2021 12:49:15 +0900 Subject: x86: remove x86-specific cmd_barebox__ 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 Link: https://lore.barebox.org/20211117034918.1226358-3-masahiroy@kernel.org Signed-off-by: Sascha Hauer --- arch/x86/Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 9fc64cc047..c73842cf86 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 \ -- cgit v1.2.3 From 22c565ae385d4f1e1028e278977c3e03bdef4c26 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 17 Nov 2021 12:49:16 +0900 Subject: x86: stop copying unneeded sections to barebox.efi Stop copying the following sections: __barebox_initcalls __barebox_exitcalls __barebox_cmd .barebox_magic Such sections do not exist. Signed-off-by: Masahiro Yamada Link: https://lore.barebox.org/20211117034918.1226358-4-masahiroy@kernel.org Signed-off-by: Sascha Hauer --- arch/x86/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index c73842cf86..5623b2cea5 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 -- cgit v1.2.3 From cbe94d33fe10a069b66b2ce558db3b7acffe6e5a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 17 Nov 2021 12:49:17 +0900 Subject: x86: reuse cmd_objcopy to generate barebox.efi The objcopy rule is defined in scripts/Makefile.lib Reuse it. Signed-off-by: Masahiro Yamada Link: https://lore.barebox.org/20211117034918.1226358-5-masahiroy@kernel.org Signed-off-by: Sascha Hauer --- arch/x86/Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5623b2cea5..53cbd50881 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 -- cgit v1.2.3 From ba80c6eaec11bd522db970ba9c4849dcb349c994 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 17 Nov 2021 12:49:18 +0900 Subject: x86_64: do not pass the EFI image handle or system table to relocation 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 Link: https://lore.barebox.org/20211117034918.1226358-6-masahiroy@kernel.org Signed-off-by: Sascha Hauer --- 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 aa03106e9c..d23c1fb2d6 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 e83bacb302..f015ae047d 100644 --- a/arch/x86/mach-efi/reloc_x86_64.c +++ b/arch/x86/mach-efi/reloc_x86_64.c @@ -41,9 +41,9 @@ #include -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; -- cgit v1.2.3