Skip to contentSkip to conversation

x86: misc cleanups

PATCH Applied Masahiro Yamada 2 participants 7 messages Nov 17, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover x86: misc cleanups

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

 arch/kvx/Makefile                   |  2 +-
 arch/mips/Makefile                  |  2 --
 arch/riscv/Makefile                 |  1 -
 arch/x86/Makefile                   | 23 ++++++++---------------
 arch/x86/mach-efi/crt0-efi-x86_64.S |  6 +-----
 arch/x86/mach-efi/reloc_x86_64.c    |  4 ++--
 6 files changed, 12 insertions(+), 26 deletions(-)
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/5 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.)

---

 arch/kvx/Makefile   | 2 +-
 arch/mips/Makefile  | 2 --
 arch/riscv/Makefile | 1 -
 arch/x86/Makefile   | 2 +-
 4 files changed, 2 insertions(+), 5 deletions(-)
arch/kvx/Makefile +1 -1
index 13c4e2431..f29eeef92 100644
@@ -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))
arch/mips/Makefile +0 -2
index 4eb6ba772..786695194 100644
@@ -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
arch/riscv/Makefile +0 -1
index 0b1278936..23ea6178a 100644
@@ -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)
 
arch/x86/Makefile +1 -1
index fd871ca21..9fc64cc04 100644
@@ -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 ,$^)
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/5 x86: remove x86-specific cmd_barebox__

In reply to 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__.

---

 arch/x86/Makefile | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
arch/x86/Makefile +3 -8
index 9fc64cc04..c73842cf8 100644
@@ -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 \
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/5 x86: stop copying unneeded sections to barebox.efi

In reply to Masahiro Yamada

Stop copying the following sections:

__barebox_initcalls
__barebox_exitcalls
__barebox_cmd
.barebox_magic

Such sections do not exist.

---

 arch/x86/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/Makefile +1 -2
index c73842cf8..5623b2cea 100644
@@ -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
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/5 x86: reuse cmd_objcopy to generate barebox.efi

In reply to Masahiro Yamada

The objcopy rule is defined in scripts/Makefile.lib

Reuse it.

---

 arch/x86/Makefile | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/x86/Makefile +5 -6
index 5623b2cea..53cbd5088 100644
@@ -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
 
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/5 x86_64: do not pass the EFI image handle or system table to relocation

In reply to 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.

---

 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(-)
arch/x86/mach-efi/crt0-efi-x86_64.S +1 -5
index aa03106e9..d23c1fb2d 100644
@@ -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
arch/x86/mach-efi/reloc_x86_64.c +2 -2
index e83bacb30..f015ae047 100644
@@ -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;
Signature · 7 lines
2.30.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#6 lore raw
In reply to Masahiro Yamada
Quoted 9 lines · Masahiro Yamada

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox