RISC-V: Fix the VDSO symbol generaton for binutils-2.34+
Subsystems (2)
PATCH 1/1 RISC-V: Fix the VDSO symbol generaton for binutils-2.34+
We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.34 (specifically the binutils-gdb commit a87e1817a4 ("Have the linker fail if any attempt to link in an executable is made."), which IIUC landed in 2.34), which recently installed itself on my build setup.
The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue.
--- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 19 +++++++++---------- arch/riscv/kernel/vdso/so2s.sh | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sh
arch/riscv/kernel/vdso/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.S
arch/riscv/kernel/vdso/Makefile +9 -10
@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -68,11 +63,15 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@ cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o [email protected] && \ + -Wl,-T,$(filter-out FORCE,$^) -o [email protected] -Wl,-Map,[email protected] && \ $(CROSS_COMPILE)objcopy \ $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ rm [email protected] +# Extracts +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(CROSS_COMPILE)nm -D $< | $(src)/so2s.sh > $@ + # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/[email protected] $(MODLIB)/vdso/$@
arch/riscv/kernel/vdso/so2s.sh new file +6 -0
@@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt <[email protected]> + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)@@LINUX_4.15!.global \2\n.set \2,0x\1!' \ +| grep '^\.'
Signature · 7 lines
2.29.0.rc1.297.gfa9743e501-goog _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 17 lines · Palmer Dabbelt' via Clang Built Linux
We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.34 (specifically the binutils-gdb commit
a87e1817a4("Have the linker fail if any attempt to link in an executable is made."), which IIUC landed in 2.34), which recently installed itself on my build setup.The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue.
Quoted 4 lines
Fixes e2c0cdfba7f6 ("RISC-V: User-facing API")Signed-off-by Palmer Dabbelt <[email protected]>
Ah, I do see a build failure to link the vdso with:
$ riscv64-linux-gnu-ld --version GNU ld (GNU Binutils for Debian) 2.34.90.20200706
riscv64-linux-gnu-ld: cannot use executable file 'arch/riscv/kernel/vdso/vdso-dummy.o' as input to a link
This patch fixes that for me, but there's a problem related to related to nm below.
After this, there's two other things we might want to fix up related to the build of the vdso:
1. it looks like $(CC) is being used to link the vdso, rather than $(LD). While it's generally fine to use the compiler as the driver for building a linked object file, it does not respect the set $(LD). -fuse-ld= needs to be passed to invoke the linker the user specified. See also:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#u
(this has popped up in a few places when trying to do hermetic builds with LLD).
2. I observe the warning when building with clang: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]. IIRC, the top level Makefile sets -Qunused-arguments for builds with clang. cmd_vdsold may need that, but it's curious why it's unused and makes me wonder why/if -no-pie is necessary? That also might be fixed by fixing 1.
Quoted 47 lines
--- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 19 +++++++++---------- arch/riscv/kernel/vdso/so2s.sh | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sharch/riscv/kernel/vdso/.gitignore +1
-0@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.Sarch/riscv/kernel/vdso/Makefile +4
-9@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S@@ -68,11 +63,15 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 73
Quoted 10 lines
arch/riscv/kernel/vdso/Makefile +4
-1cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o [email protected] && \ + -Wl,-T,$(filter-out FORCE,$^) -o [email protected] -Wl,-Map,[email protected] && \ $(CROSS_COMPILE)objcopy \ $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ rm [email protected] +# Extracts +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(CROSS_COMPILE)nm -D $< | $(src)/so2s.sh > $@
This should use $(NM) rather than $(CROSS_COMPILE)nm which hardcodes the use of GNU nm from GNU binutils.
Quoted 17 lines
arch/riscv/kernel/vdso/Makefile +1
-0+ # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/[email protected] $(MODLIB)/vdso/$@arch/riscv/kernel/vdso/so2s.sh new file +6
-1@@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt <[email protected]> + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)@@LINUX_4.15!.global \2\n.set \2,0x\1!' \ +| grep '^\.' --
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 9 lines · Nick Desaulniers' via Clang Built Linux
Quoted 7 lines · Palmer Dabbelt' via Clang Built Linux
We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.34 (specifically the binutils-gdb commit
a87e1817a4("Have the linker fail if any attempt to link in an executable is made."), which IIUC landed in 2.34), which recently installed itself on my build setup.
I filed the issue https://sourceware.org/bugzilla/show_bug.cgi?id=26047
The commit is in 2.35 but not in the released 2.34 branch.
Quoted 83 lines
Quoted 9 lines
The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue.
Quoted 4 lines
Fixes e2c0cdfba7f6 ("RISC-V: User-facing API")Signed-off-by Palmer Dabbelt <[email protected]>Ah, I do see a build failure to link the vdso with:
$ riscv64-linux-gnu-ld --version GNU ld (GNU Binutils for Debian) 2.34.90.20200706riscv64-linux-gnu-ld: cannot use executable file '
arch/riscv/kernel/vdso/vdso-dummy.o' as input to a linkThis patch fixes that for me, but there's a problem related to related to
nmbelow.After this, there's two other things we might want to fix up related to the build of the vdso:
1. it looks like $(CC) is being used to link the vdso, rather than $(LD). While it's generally fine to use the compiler as the driver for building a linked object file, it does not respect the set $(LD).-fuse-ld=needs to be passed to invoke the linker the user specified. See also:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#u
(this has popped up in a few places when trying to do hermetic builds with LLD).
2. I observe the warning when building with clang:argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]. IIRC, the top levelMakefilesets-Qunused-argumentsfor builds with clang.cmd_vdsoldmay need that, but it's curious why it's unused and makes me wonder why/if-no-pieis necessary? That also might be fixed by fixing 1.Quoted 42 lines
--- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 19 +++++++++---------- arch/riscv/kernel/vdso/so2s.sh | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sharch/riscv/kernel/vdso/.gitignore +1
-0@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.Sarch/riscv/kernel/vdso/Makefile +4
-9@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s)
Quoted 8 lines
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 66
Quoted 8 lines
arch/riscv/kernel/vdso/Makefile +1
-1# strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S@@ -68,11 +63,15 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@ cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o [email protected] && \ + -Wl,-T,$(filter-out FORCE,$^) -o [email protected] -Wl,-Map,[email protected] && \
Is -Wl,-Map,[email protected] needed?
Quoted 37 lines
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 73
Quoted 7 lines
arch/riscv/kernel/vdso/Makefile +3
-0$(CROSS_COMPILE)objcopy \ $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ rm [email protected] +# Extracts +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(CROSS_COMPILE)nm -D $< | $(src)/so2s.sh > $@This should use
$(NM)rather than$(CROSS_COMPILE)nmwhich hardcodes the use of GNU nm from GNU binutils.Quoted 17 lines
arch/riscv/kernel/vdso/Makefile +1
-0+ # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/[email protected] $(MODLIB)/vdso/$@arch/riscv/kernel/vdso/so2s.sh new file +6
-1@@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt <[email protected]> + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)@@LINUX_4.15!.global \2\n.set \2,0x\1!' \ +| grep '^\.' --Signature · 7 lines
Thanks, ~Nick Desaulniers -- You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdnsRHA1WMb7OWi-jV662xLrBBBZ%3DzBbB1gvfpBqVFeSfQ%40mail.gmail.com.
Quoted 11 lines · On Mon, 19 Oct 2020 13:41:21 PDT (-0700), [email protected] wrote:
Quoted 9 lines · Nick Desaulniers' via Clang Built Linux
Quoted 7 lines · Palmer Dabbelt' via Clang Built Linux
We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.34 (specifically the binutils-gdb commit
a87e1817a4("Have the linker fail if any attempt to link in an executable is made."), which IIUC landed in 2.34), which recently installed itself on my build setup.
Quoted 2 lines
I filed the issue https://sourceware.org/bugzilla/show_bug.cgi?id=26047
The commit is in 2.35 but not in the released 2.34 branch.
Thanks. Looks like it was backported to the Debian 2.34, I guess I was off by a release when looking. Regardless, I think the fix in binutils is reasonable and that we just shouldn't be doing this sort of thing.
Quoted 83 lines
Quoted 83 lines
Quoted 9 lines
The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue.
Quoted 4 lines
Fixes e2c0cdfba7f6 ("RISC-V: User-facing API")Signed-off-by Palmer Dabbelt <[email protected]>Ah, I do see a build failure to link the vdso with:
$ riscv64-linux-gnu-ld --version GNU ld (GNU Binutils for Debian) 2.34.90.20200706riscv64-linux-gnu-ld: cannot use executable file '
arch/riscv/kernel/vdso/vdso-dummy.o' as input to a linkThis patch fixes that for me, but there's a problem related to related to
nmbelow.After this, there's two other things we might want to fix up related to the build of the vdso:
1. it looks like $(CC) is being used to link the vdso, rather than $(LD). While it's generally fine to use the compiler as the driver for building a linked object file, it does not respect the set $(LD).-fuse-ld=needs to be passed to invoke the linker the user specified. See also:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#u
(this has popped up in a few places when trying to do hermetic builds with LLD).
2. I observe the warning when building with clang:argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]. IIRC, the top levelMakefilesets-Qunused-argumentsfor builds with clang.cmd_vdsoldmay need that, but it's curious why it's unused and makes me wonder why/if-no-pieis necessary? That also might be fixed by fixing 1.Quoted 42 lines
--- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 19 +++++++++---------- arch/riscv/kernel/vdso/so2s.sh | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sharch/riscv/kernel/vdso/.gitignore +1
-0@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.Sarch/riscv/kernel/vdso/Makefile +4
-9@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s)
Quoted 10 lines
Quoted 8 lines
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 66
Quoted 8 lines
arch/riscv/kernel/vdso/Makefile +1
-1# strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S@@ -68,11 +63,15 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@ cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o [email protected] && \ + -Wl,-T,$(filter-out FORCE,$^) -o [email protected] -Wl,-Map,[email protected] && \Is -Wl,-Map,[email protected] needed?
Nope, that's there be accident. I've fixed it for the v2.
Thanks!
Quoted 38 lines
Quoted 38 lines
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 73
Quoted 8 lines
arch/riscv/kernel/vdso/Makefile +3
-0$(CROSS_COMPILE)objcopy \ $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ rm [email protected] +# Extracts +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(CROSS_COMPILE)nm -D $< | $(src)/so2s.sh > $@This should use
$(NM)rather than$(CROSS_COMPILE)nmwhich hardcodes the use of GNU nm from GNU binutils.Quoted 10 lines
arch/riscv/kernel/vdso/Makefile +1
-0+ # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/[email protected] $(MODLIB)/vdso/$@arch/riscv/kernel/vdso/so2s.sh new file +0
-0arch/riscv/kernel/vdso/so2s.sh
Quoted 7 lines
arch/riscv/kernel/vdso/so2s.sh new file +6
-1@@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt <[email protected]> + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)@@LINUX_4.15!.global \2\n.set \2,0x\1!' \ +| grep '^\.' ----
Thanks,
~Nick Desaulniers--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAKwvOdnsRHA1WMb7OWi-jV662xLrBBBZ%3DzBbB1gvfpBqVFeSfQ%40mail.gmail.com.
Quoted 24 lines · Nick Desaulniers
Quoted 17 lines · Palmer Dabbelt' via Clang Built Linux
We were relying on GNU ld's ability to re-link executable files in order to extract our VDSO symbols. This behavior was deemed a bug as of binutils-2.34 (specifically the binutils-gdb commit
a87e1817a4("Have the linker fail if any attempt to link in an executable is made."), which IIUC landed in 2.34), which recently installed itself on my build setup.The previous version of this was a bit of a mess: we were linking a static executable version of the VDSO, containing only a subset of the input symbols, which we then linked into the kernel. This worked, but certainly wasn't a supported path through the toolchain. Instead this new version parses the textual output of nm to produce a symbol table. Both rely on near-zero addresses being linkable, but as we rely on weak undefined symbols being linkable elsewhere I don't view this as a major issue.
Quoted 4 lines
Fixes e2c0cdfba7f6 ("RISC-V: User-facing API")Signed-off-by Palmer Dabbelt <[email protected]>
Quoted 6 lines
Ah, I do see a build failure to link the vdso with:
$ riscv64-linux-gnu-ld --version GNU ld (GNU Binutils for Debian) 2.34.90.20200706riscv64-linux-gnu-ld: cannot use executable file '
arch/riscv/kernel/vdso/vdso-dummy.o' as input to a link
Ya, looks like it was actually a backport.
Quoted 13 lines
This patch fixes that for me, but there's a problem related to related to
nmbelow.After this, there's two other things we might want to fix up related to the build of the vdso:
1. it looks like $(CC) is being used to link the vdso, rather than $(LD). While it's generally fine to use the compiler as the driver for building a linked object file, it does not respect the set $(LD).-fuse-ld=needs to be passed to invoke the linker the user specified. See also:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#u
(this has popped up in a few places when trying to do hermetic builds with LLD).
It's probably just to make the argument handling easier -- I generally avoid invoking the linker directly and instead just always use CC because I can never remember the linker arguments.
Quoted 6 lines
2. I observe the warning when building with clang:
argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]. IIRC, the top levelMakefilesets-Qunused-argumentsfor builds with clang.cmd_vdsoldmay need that, but it's curious why it's unused and makes me wonder why/if-no-pieis necessary? That also might be fixed by fixing 1.
That seems odd: vdsold is only used for a link, and -no-pie is necessary for linking.
Quoted 55 lines
Quoted 55 lines
--- arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 19 +++++++++---------- arch/riscv/kernel/vdso/so2s.sh | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100755 arch/riscv/kernel/vdso/so2s.sharch/riscv/kernel/vdso/.gitignore +1
-0@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso.lds *.tmp +vdso-syms.Sarch/riscv/kernel/vdso/Makefile +5
-10@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so SYSCFLAGS_vdso.so.dbg = $(c_flags) $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE $(call if_changed,vdsold) +SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ + -Wl,--build-id -Wl,--hash-style=both # We also create a special relocatable object that should mirror the symbol # table and layout of the linked DSO. With ld --just-symbols we can then # refer to these symbols in the kernel code rather than hand-coded addresses. - -SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ - -Wl,--build-id -Wl,--hash-style=both -$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE - $(call if_changed,vdsold) - -LDFLAGS_vdso-syms.o := -r --just-symbols -$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE - $(call if_changed,ld) +$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE + $(call if_changed,so2s) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S@@ -68,11 +63,15 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # Make sure only to export the intended __vdso_xxx symbol offsets. quiet_cmd_vdsold = VDSOLD $@ cmd_vdsold = $(CC) $(KBUILD_CFLAGS) $(call cc-option, -no-pie) -nostdlib -nostartfiles $(SYSCFLAGS_$(@F)) \ - -Wl,-T,$(filter-out FORCE,$^) -o [email protected] && \ + -Wl,-T,$(filter-out FORCE,$^) -o [email protected] -Wl,-Map,[email protected] && \ $(CROSS_COMPILE)objcopy \ $(patsubst %, -G __vdso_%, $(vdso-syms)) [email protected] $@ && \ rm [email protected]
Quoted 6 lines
arch/riscv/kernel/vdso/Makefile $(obj)/%.so: $(obj)/%.so.dbg FORCE · line 73
Quoted 3 lines
arch/riscv/kernel/vdso/Makefile +3
-0+# Extracts +quiet_cmd_so2s = SO2S $@ + cmd_so2s = $(CROSS_COMPILE)nm -D $< | $(src)/so2s.sh > $@This should use
$(NM)rather than$(CROSS_COMPILE)nmwhich hardcodes the use of GNU nm from GNU binutils.
Thanks, this is fixed in the v2. Presumably we should be using $(OBJCOPY) as well?
Quoted 18 lines
Quoted 18 lines
arch/riscv/kernel/vdso/Makefile +1
-0+ # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ cmd_vdso_install = cp $(obj)/[email protected] $(MODLIB)/vdso/$@arch/riscv/kernel/vdso/so2s.sh new file +6
-1@@ -0,0 +1,6 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Palmer Dabbelt <[email protected]> + +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)@@LINUX_4.15!.global \2\n.set \2,0x\1!' \ +| grep '^\.' --