Sunday, November 29, 2020

Re: gcc --static produces programs that crash

On Sat, 28 Nov 2020 12:45:10 +0000
Stuart Henderson <stu@spacehopper.org> wrote:

> On 2020/11/28 12:26, helmut karlowski wrote:
> > $ldd a.out
> > a.out:
> > Start End Type Open Ref GrpRef Name
> > 1a52f000 3a537000 exe 1 0 0 a.out
> > 0302c000 0302c000 ld.so 0 1 0 /usr/libexec/ld.so
>
> OpenBSD compilers use PIE by default, this is normal for a PIE binary.

OpenBSD doesn't use ld.so for static pie.

This diff might fix the problem. This diff was in one of my ports
trees, but I forgot about it. The diff was from j@bitminer.ca in
"fix GCC 8.4.0 to unbreak -static linking" [1], except that this one
also edits patch-gcc_config_rs6000_openbsd_h for powerpc. I forget if
it works, so I will begin rechecking it.

[1] https://marc.info/?l=openbsd-ports&m=159967716702259&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 30 Nov 2020 03:24:18 -0000
@@ -36,6 +36,8 @@ PKGNAME-objc = gobjc-${FULL_PKGVERSION}
PKGNAME-ada = gnat-${FULL_PKGVERSION}
PKGSPEC-main = gcc->=8,<9

+REVISION = 0
+
SHARED_LIBS = estdc++ 19.0 \
gfortran 8.0 \
objc 8.0 \
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 30 Nov 2020 03:24:18 -0000
@@ -57,7 +57,7 @@ Index: gcc/config/aarch64/openbsd.h
+ %{!static:-Bdynamic} \
+ %{rdynamic:-export-dynamic} \
+ %{assert*} \
-+ %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
++ %{!shared:%{!static:%{!-dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}} \
+ -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 30 Nov 2020 03:24:18 -0000
@@ -2,7 +2,7 @@ $OpenBSD: patch-gcc_config_alpha_openbsd
Index: gcc/config/alpha/openbsd.h
--- gcc/config/alpha/openbsd.h.orig
+++ gcc/config/alpha/openbsd.h
-@@ -19,6 +19,28 @@ along with GCC; see the file COPYING3. If not see
+@@ -19,6 +19,28 @@ along with GCC; see the file COPYING3.

/* Controlling the compilation driver. */

@@ -17,7 +17,7 @@ Index: gcc/config/alpha/openbsd.h
+ %{!static:-Bdynamic} \
+ %{rdynamic:-export-dynamic} \
+ %{assert*} \
-+ %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}"
++ %{!shared:%{!static:%{!-dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}}"
+
+/* As an elf system, we need crtbegin/crtend stuff. */
+#undef STARTFILE_SPEC
@@ -31,7 +31,7 @@ Index: gcc/config/alpha/openbsd.h
/* run-time target specifications */
#define TARGET_OS_CPP_BUILTINS() \
do { \
-@@ -28,18 +50,27 @@ along with GCC; see the file COPYING3. If not see
+@@ -28,18 +50,27 @@ along with GCC; see the file COPYING3.

/* Layout of source language data types. */

@@ -54,9 +54,9 @@ Index: gcc/config/alpha/openbsd.h

#undef WCHAR_TYPE_SIZE
#define WCHAR_TYPE_SIZE 32
-+
+
+#undef WINT_TYPE
+#define WINT_TYPE "int"
-
++

#define LOCAL_LABEL_PREFIX "."
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 30 Nov 2020 03:24:18 -0000
@@ -82,7 +82,7 @@ Index: gcc/config/arm/openbsd.h
+ %{!static:-Bdynamic} \
+ %{rdynamic:-export-dynamic} \
+ %{assert*} \
-+ %{!shared:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
++ %{!shared:%{!static:%{!-dynamic-linker:-dynamic-linker /usr/libexec/ld.so}}} \
+ %{!nostdlib:-L/usr/lib}"
+

No comments:

Post a Comment