Skip to contentSkip to conversation

riscv: fix vdso build with lld

PATCH Superseded Ilie Halip 3 participants 3 messages Apr 2, 2020 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ilie Halip

author
#0 lore raw

PATCH 1/1 riscv: fix vdso build with lld

When building with the LLVM linker this error occurrs:
LD arch/riscv/kernel/vdso/vdso-syms.o
ld.lld: error: no input files

This happens because the lld treats -R as an alias to -rpath, as opposed to ld where -R means --just-symbols.

Use the long option name for compatibility between the two.

---
 arch/riscv/kernel/vdso/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/vdso/Makefile +2 -1
index 33b16f4212f7..19f7b9ea10ab 100644
@@ -41,7 +41,8 @@ SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
 	$(call if_changed,vdsold)
 
-LDFLAGS_vdso-syms.o := -r -R
+# lld aliases -R to -rpath; use the longer option name
+LDFLAGS_vdso-syms.o := -r --just-symbols
 $(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
 	$(call if_changed,ld)
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

+ Jordan, Fangrui

Quoted 22 lines · Ilie Halip

When building with the LLVM linker this error occurrs:
LD arch/riscv/kernel/vdso/vdso-syms.o
ld.lld: error: no input files

This happens because the lld treats -R as an alias to -rpath, as opposed to ld where -R means --just-symbols.

Use the long option name for compatibility between the two.

---
 arch/riscv/kernel/vdso/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/vdso/Makefile +0 -0
index 33b16f4212f7..19f7b9ea10ab 100644

arch/riscv/kernel/vdso/Makefile SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ · line 44

Quoted 5 lines
arch/riscv/kernel/vdso/Makefile +1 -1
@@ -41,7 +41,8 @@ SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
        $(call if_changed,vdsold)
 
-LDFLAGS_vdso-syms.o := -r -R
+# lld aliases -R to -rpath; use the longer option name

Thanks for the patch. Maybe the comment can be dropped? It doesn't make sense if there's no -R in the source file you're touching. If someone cares about why --just-symbols is spelled out, that's what git log or vim fugitive is for. Maybe the maintainer would be kind enough to just drop that line for you when merging?

Jordan, Fangrui, thoughts on this? Sounds like something other users of LLD might run into porting their codebase to LLVM's linker.

$ ld.lld --help | grep \\-R
  -R <value>              Alias for --rpath
$ ld.bfd --help | grep \\-R
  -R FILE, --just-symbols FILE
Quoted 7 lines
arch/riscv/kernel/vdso/Makefile +1 -1
+LDFLAGS_vdso-syms.o := -r --just-symbols
 $(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
        $(call if_changed,ld)
 
--

2.17.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw

The comment of With ld -R we can then ... should be fixed as well.

Quoted 37 lines · Nick Desaulniers

+ Jordan, Fangrui

Quoted 22 lines · Ilie Halip

When building with the LLVM linker this error occurrs:
LD arch/riscv/kernel/vdso/vdso-syms.o
ld.lld: error: no input files

This happens because the lld treats -R as an alias to -rpath, as opposed to ld where -R means --just-symbols.

Use the long option name for compatibility between the two.

---
 arch/riscv/kernel/vdso/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/vdso/Makefile +0 -0
index 33b16f4212f7..19f7b9ea10ab 100644

arch/riscv/kernel/vdso/Makefile SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \ · line 44

Quoted 5 lines
arch/riscv/kernel/vdso/Makefile +1 -1
@@ -41,7 +41,8 @@ SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
 $(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
        $(call if_changed,vdsold)
 
-LDFLAGS_vdso-syms.o := -r -R
+# lld aliases -R to -rpath; use the longer option name

Thanks for the patch. Maybe the comment can be dropped? It doesn't make sense if there's no -R in the source file you're touching. If someone cares about why --just-symbols is spelled out, that's what git log or vim fugitive is for. Maybe the maintainer would be kind enough to just drop that line for you when merging?

Quoted 4 lines

Jordan, Fangrui, thoughts on this? Sounds like something other users of LLD might run into porting their codebase to LLVM's linker.

Independently, I noticed this ~2 days ago.
https://reviews.llvm.org/D76885#1952860

GNU ld parses options with getopt_long and -j is recognized as --just-symbols ('R') because there is no other long options prefixed with -j.

Now, the following comment applies. Basically, --just-symbols/-R is an overloaded option. It can be used as an -rpath if the argument is a directory. The best practice is to use either -rpath or --just-symbols, never -R.

// binutils-gdb/ld/lexsup.c

	case 'R':
	  /* The GNU linker traditionally uses -R to mean to include
	     only the symbols from a file.  The Solaris linker uses -R
	     to set the path used by the runtime linker to find
	     libraries.  This is the GNU linker -rpath argument.  We
	     try to support both simultaneously by checking the file
	     named.  If it is a directory, rather than a regular file,
	     we assume -rpath was meant.  */
	  {
	    struct stat s;

	    if (stat (optarg, &s) >= 0
		&& ! S_ISDIR (s.st_mode))
	      {
		lang_add_input_file (optarg,
				     lang_input_file_is_symbols_only_enum,
				     NULL);
		break;
	      }
	  }
Quoted 17 lines
$ ld.lld --help | grep \\-R
 -R <value>              Alias for --rpath
$ ld.bfd --help | grep \\-R
 -R FILE, --just-symbols FILE
Quoted 7 lines
arch/riscv/kernel/vdso/Makefile +1 -1
+LDFLAGS_vdso-syms.o := -r --just-symbols
 $(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
        $(call if_changed,ld)
 
--

2.17.1

Signature · 2 lines
Thanks,
~Nick Desaulniers