Here is a tgz file for a test suite: it fails as expected for -static
on 6.8-release and succeeds on a recent snap with your patch -- on arm64.

I have added a -nostdlib test and cleanup up error messages.

John


On 2020-12-03 19:34, j...@bitminer.ca wrote:
Hi George,


On 2020-12-02 19:57, George Koehler wrote:
This diff in lang/gcc/8 works for me on amd64 and powerpc.  I would
like tests on more arches.  Is it ok to commit?

I tested this diff on a Raspberry Pi4 (aarch64) and it succeeds with
testing -Bdynamic or -static for Fortran and C, and
checking the -R option for c++.  These tests fail for -static
on a stock 6.8 release.


for linking in "-Bdynamic" "-static" ; do

  echo linking is ${linking}
  egfortran -o fworks fworks.f90 ${linking}
  ./fworks || echo "                " Fortran ${linking} fails

  egcc      -o cworks cworks.c   ${linking}
  ./cworks || echo "                " CC ${linking} fails

done

eg++ -fPIC -shared cppshare.cpp -o libcppshare.so
eg++ -L . -lcppshare -o cppworks cppworks.cpp
./cppworks && echo " ./cppworks somehow finds local libcppshare.so
without LD_LIBRARY_PATH!!!"
LD_LIBRARY_PATH=. ./cppworks

eg++ -L . -lcppshare -o cppworks cppworks.cpp -R `pwd`
./cppworks || echo " cant find local libcppshare.so with -R option"


So I believe I have covered most of your diff with these tests, except
the -nostdlib parsing.



John



This diff makes 4 changes to LINK_SPEC:
  1. use "%{!static:-dynamic-linker /usr/libexec/ld.so}" to fix
     static linking; you can try the Fortran example below.
  2. change %{r*:} to %{r:}; base-gcc uses %{r*:}, but upstream
     changed %{r*:} to %{r:} in commit 7aed7df [1].
  3. change -L/usr/lib to %{!nostdlib:-L/usr/lib} to be like base-gcc.
  4. rewrite powerpc's *_rs6000_openbsd_h to be like other arches,
     and add %{!nostdlib:-L/usr/lib} so I can try lld on powerpc.

$ cat works.f90
print *, 'Fortran works.'
end
$ egfortran -o works works.f90 -static
$ ./works
 Fortran works.

%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}}
  means if not "gcc -shared" and not "gcc -nostdlib" and not "gcc -r"
  and not "gcc -e something_else", then run "ld -e __start".  We don't
  need this spec on arches like powerpc, where ld's default entry is
  __start, but I added this spec to powerpc to be like other arches.
%{shared:-shared}
  means if "gcc -shared" then "ld -shared".
%{R*}
  means if "gcc -R/some/dir" then "ld -R /some/dir".  This had been
  missing on powerpc, where "gcc -R/some/dir" got ignored.
%{static:-Bstatic}
  means if "gcc -static" then "ld -Bstatic".  We need this to tell ld
  to avoid shared libs when linking static bins.  powerpc was using
  "ld -static", but I changed it to -Bstatic to be like other arches.
%{!static:-Bdynamic}
  might not be needed, but I kept it and added it to powerpc.
%{rdynamic:-export-dynamic}
  was added by our patches, and I kept it.
%{assert*}
  is useless.  The intent is "gcc -assert X" => "ld -assert X", but
  gcc rejects -assert and uses --assert for Fortran.  I didn't delete
  the %{assert*} because upstream hadn't deleted it.
%{!static:-dynamic-linker /usr/libexec/ld.so}
  fixes static linking.  base-gcc uses the longer spec
  %{!static:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}
  but there is no such option "gcc -dynamic-linker X"; upstream
  deleted %{!dynamic-linker:} in commit e59dabd [2].
%{!nostdlib:-L/usr/lib}
  is for lld to search /usr/lib.  There is a bug, for which I don't
  know the fix: this spec passes -L/usr/lib too early, so the search
  order is /usr/lib before anything else, and you can't tell gcc to
  use your own libcurses.a instead of the one in /usr/lib [3].

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7aed7dfc45e81230bd4fa01c16b55c0904b49535 [2] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e59dabd237f24b87814a3664e2f092c2b107facf
[3] https://marc.info/?l=openbsd-bugs&m=156547894114050&w=2

Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/gcc/8/Makefile,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile
--- Makefile    14 Nov 2020 00:00:39 -0000      1.36
+++ Makefile    2 Dec 2020 04:27:15 -0000
@@ -18,7 +18,7 @@ DPB_PROPERTIES = parallel
 V = 8.4.0
 FULL_VERSION = $V
 FULL_PKGVERSION = $V
-REVISION = 1
+REVISION = 2

 ADASTRAP-amd64 = adastrap-amd64-8.3.0-2.tar.xz
 ADASTRAP-arm = adastrap-arm-4.9.4-0.tar.xz
Index: patches/patch-gcc_config_aarch64_openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_aarch64_openbsd_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_aarch64_openbsd_h
--- patches/patch-gcc_config_aarch64_openbsd_h 20 May 2019 14:59:05 -0000 1.2 +++ patches/patch-gcc_config_aarch64_openbsd_h 2 Dec 2020 04:27:15 -0000
@@ -51,14 +51,14 @@ Index: gcc/config/aarch64/openbsd.h
 +#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC
 +
 +#define LINK_SPEC \
-+  "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \
++  "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \
 +   %{shared:-shared} %{R*} \
 +   %{static:-Bstatic} \
 +   %{!static:-Bdynamic} \
 +   %{rdynamic:-export-dynamic} \
 +   %{assert*} \
-+ %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
-+   -L/usr/lib"
++   %{!static:-dynamic-linker /usr/libexec/ld.so} \
++   %{!nostdlib:-L/usr/lib}"
 +
 +#define OPENBSD_ENTRY_POINT "__start"
 +
Index: patches/patch-gcc_config_alpha_openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_alpha_openbsd_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_alpha_openbsd_h
--- patches/patch-gcc_config_alpha_openbsd_h 20 May 2019 14:59:05 -0000 1.2
+++ patches/patch-gcc_config_alpha_openbsd_h    2 Dec 2020 04:27:15 -0000
@@ -10,14 +10,14 @@ Index: gcc/config/alpha/openbsd.h
 +#define TARGET_DEFAULT \
 +      (MASK_FPREGS | MASK_IEEE | MASK_IEEE_CONFORMANT)
 +
-+ #define LINK_SPEC \
-+  "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \
++#define LINK_SPEC \
++  "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \
 +   %{shared:-shared} %{R*} \
 +   %{static:-Bstatic} \
 +   %{!static:-Bdynamic} \
 +   %{rdynamic:-export-dynamic} \
 +   %{assert*} \
-+   %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}"
++   %{!static:-dynamic-linker /usr/libexec/ld.so}"
 +
 +/* As an elf system, we need crtbegin/crtend stuff.  */
 +#undef STARTFILE_SPEC
Index: patches/patch-gcc_config_arm_openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_arm_openbsd_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_arm_openbsd_h
--- patches/patch-gcc_config_arm_openbsd_h 20 May 2019 14:59:05 -0000 1.2
+++ patches/patch-gcc_config_arm_openbsd_h      2 Dec 2020 04:27:15 -0000
@@ -73,16 +73,16 @@ Index: gcc/config/arm/openbsd.h
 +#undef OBSD_LINK_SPEC
 +#ifdef OBSD_NO_DYNAMIC_LIBRARIES
 +#define OBSD_LINK_SPEC \
-+  "%{!nostdlib:%{!r*:%{!e*:-e __start}}} %{assert*}"
++  "%{!nostdlib:%{!r:%{!e*:-e __start}}} %{assert*}"
 +#else
 +#define OBSD_LINK_SPEC \
-+  "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \
++  "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \
 +   %{shared:-shared} %{R*} \
 +   %{static:-Bstatic} \
 +   %{!static:-Bdynamic} \
 +   %{rdynamic:-export-dynamic} \
 +   %{assert*} \
-+ %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
++   %{!static:-dynamic-linker /usr/libexec/ld.so} \
 +   %{!nostdlib:-L/usr/lib}"
 +#endif
 +
Index: patches/patch-gcc_config_i386_openbsdelf_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_i386_openbsdelf_h,v
retrieving revision 1.3
diff -u -p -r1.3 patch-gcc_config_i386_openbsdelf_h
--- patches/patch-gcc_config_i386_openbsdelf_h 8 Aug 2020 16:48:48 -0000 1.3 +++ patches/patch-gcc_config_i386_openbsdelf_h 2 Dec 2020 04:27:15 -0000
@@ -10,8 +10,8 @@ Index: gcc/config/i386/openbsdelf.h
 +   %{rdynamic:-export-dynamic} \
     %{assert*} \
 -   -dynamic-linker /usr/libexec/ld.so"
-+ %{!shared:%{!-dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
-+   -L/usr/lib"
++   %{!static:-dynamic-linker /usr/libexec/ld.so} \
++   %{!nostdlib:-L/usr/lib}"

  #undef STARTFILE_SPEC
 -#define STARTFILE_SPEC "\
Index: patches/patch-gcc_config_mips_openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_mips_openbsd_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_mips_openbsd_h
--- patches/patch-gcc_config_mips_openbsd_h 20 May 2019 14:59:05 -0000 1.2
+++ patches/patch-gcc_config_mips_openbsd_h     2 Dec 2020 04:27:15 -0000
@@ -142,7 +142,7 @@ Index: gcc/config/mips/openbsd.h
 +   %{!static:-Bdynamic} \
 +   %{rdynamic:-export-dynamic} \
 +   %{assert*} \
-+   %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}"
++   %{!static:-dynamic-linker /usr/libexec/ld.so}"
 +
 +/* As an elf system, we need crtbegin/crtend stuff.  */
 +#undef STARTFILE_SPEC
Index: patches/patch-gcc_config_pa_pa-openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_pa_pa-openbsd_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_pa_pa-openbsd_h
--- patches/patch-gcc_config_pa_pa-openbsd_h 20 May 2019 14:59:05 -0000 1.2
+++ patches/patch-gcc_config_pa_pa-openbsd_h    2 Dec 2020 04:27:15 -0000
@@ -9,7 +9,7 @@ Index: gcc/config/pa/pa-openbsd.h
 +   %{rdynamic:-export-dynamic} \
     %{assert*} \
 -   -dynamic-linker /usr/libexec/ld.so"
-+   %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}"
++   %{!static:-dynamic-linker /usr/libexec/ld.so}"

  #undef STARTFILE_SPEC
  #define STARTFILE_SPEC "\
Index: patches/patch-gcc_config_rs6000_openbsd_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_rs6000_openbsd_h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-gcc_config_rs6000_openbsd_h
--- patches/patch-gcc_config_rs6000_openbsd_h 4 Jan 2019 15:50:39 -0000 1.1.1.1 +++ patches/patch-gcc_config_rs6000_openbsd_h 2 Dec 2020 04:27:15 -0000
@@ -1,7 +1,8 @@
 $OpenBSD: patch-gcc_config_rs6000_openbsd_h,v 1.1.1.1 2019/01/04
15:50:39 pascal Exp $
---- gcc/config/rs6000/openbsd.h.orig   Fri Nov 15 12:47:25 2013
-+++ gcc/config/rs6000/openbsd.h        Fri Nov 15 12:49:07 2013
-@@ -0,0 +1,129 @@
+Index: gcc/config/rs6000/openbsd.h
+--- gcc/config/rs6000/openbsd.h.orig
++++ gcc/config/rs6000/openbsd.h
+@@ -0,0 +1,132 @@
 +/* Configuration file for an rs6000 OpenBSD target.
 +   Copyright (C) 1999 Free Software Foundation, Inc.
 +
@@ -63,12 +64,15 @@ $OpenBSD: patch-gcc_config_rs6000_openbs
 +#define CPP_OS_DEFAULT_SPEC "%(cpp_os_openbsd)"
 +
 +#undef LINK_SPEC
-+#define LINK_SPEC "%{shared:-shared} \
-+  %{!shared: \
-+    %{!static: \
-+      %{rdynamic:-export-dynamic} \
-+      %{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
-+    %{static:-static}}"
++#define LINK_SPEC \
++  "%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}} \
++   %{shared:-shared} %{R*} \
++   %{static:-Bstatic} \
++   %{!static:-Bdynamic} \
++   %{rdynamic:-export-dynamic} \
++   %{assert*} \
++   %{!static:-dynamic-linker /usr/libexec/ld.so} \
++   %{!nostdlib:-L/usr/lib}"
 +
 +#undef        LIB_DEFAULT_SPEC
 +#define LIB_DEFAULT_SPEC "%(lib_openbsd)"
Index: patches/patch-gcc_config_sparc_openbsd64_h
===================================================================
RCS file: /cvs/ports/lang/gcc/8/patches/patch-gcc_config_sparc_openbsd64_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-gcc_config_sparc_openbsd64_h
--- patches/patch-gcc_config_sparc_openbsd64_h 20 May 2019 14:59:05 -0000 1.2 +++ patches/patch-gcc_config_sparc_openbsd64_h 2 Dec 2020 04:27:15 -0000
@@ -68,7 +68,7 @@ Index: gcc/config/sparc/openbsd64.h
 +   %{rdynamic:-export-dynamic} \
     %{assert*} \
 -   -dynamic-linker /usr/libexec/ld.so"
-+   %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}"
++   %{!static:-dynamic-linker /usr/libexec/ld.so}"

  /* As an elf system, we need crtbegin/crtend stuff.  */
  #undef STARTFILE_SPEC

Attachment: gccports-test.tgz
Description: GNU Zip compressed data

Reply via email to