Re: [macppc / lld] devel/gmp text relocation

2021-09-09 Thread George Koehler
On Thu, 9 Sep 2021 16:15:53 +0200
Christian Weisgerber  wrote:

> George Koehler:
> 
> > WRKSRC/mpn/asm-defs.m4:1054,
> > 
> > ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
> > 
> > Notice that `PIC_ALWAYS' is in quotes, so the macro PIC_ALWAYS is not
> > expanded.  This faulty check compares the literal string "PIC_ALWAYS"
> > with the literal string "yes"; these strings never match, so this
> > faulty check never defines PIC.  I don't fix this faulty check,
> > because it might affect other archs.
> 
> It appears that check is only used on powerpc*.  The only place I
> can find that defines PIC_ALWAYS is in GMP_ASM_POWERPC_PIC_ALWAYS,
> which is indeed only called on powerpc*.
> 
> So the fix might be as simple as repairing that ifelse?

Yes, it works to repair the ifelse, so here's the new diff.  I built
it on powerpc and then packaged devel/xtensa-lx106-elf/gdb and linked
my divide.c to libgmp.a without seeing the linker error.

On powerpc, "make test" passes in both devel/gmp and
security/libnettle.  I also built the diff on powerpc64 (because
it defines PIC_ALWAYS).  "make test" in devel/gmp on powerpc64 fails
t-div, with or without today's diff.

--George

Index: Makefile
===
RCS file: /cvs/ports/devel/gmp/Makefile,v
retrieving revision 1.43
diff -u -p -r1.43 Makefile
--- Makefile17 Nov 2020 21:54:42 -  1.43
+++ Makefile9 Sep 2021 16:43:34 -
@@ -4,6 +4,7 @@ COMMENT-main=   library for arbitrary prec
 COMMENT-cxx=   C++ library for arbitrary precision arithmetic
 
 VERSION=   6.2.1
+REVISION-main= 0
 DISTNAME=  gmp-${VERSION}
 MULTI_PACKAGES=-main -cxx
 PKGNAME-main=  gmp-${VERSION}
Index: patches/patch-mpn_asm-defs_m4
===
RCS file: patches/patch-mpn_asm-defs_m4
diff -N patches/patch-mpn_asm-defs_m4
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-mpn_asm-defs_m4   9 Sep 2021 16:43:34 -
@@ -0,0 +1,25 @@
+$OpenBSD$
+
+Fix libgmp.a on powerpc, which needs the PIC asm, because OpenBSD uses
+PIE position-independent executables.  powerpc and powerpc64 define
+PIC_ALWAYS to `yes', but the quotes on `PIC_ALWAYS' broke the macro
+expansion.  This fix prevents text relocation errors on powerpc when
+ld.lld links gdb >= 8 with libgmp.a.
+
+ld: error: can't create dynamic relocation R_PPC_ADDR16_HA against local 
symbol in readonly segment; recompile object files with -fPIC or pass 
'-Wl,-z,notext' to allow text relocations in the output
+>>> defined in /usr/local/lib/libgmp.a(invert_limb.o)
+>>> referenced by tmp-invert_limb.s
+>>>   invert_limb.o:(__gmpn_invert_limb) in archive 
/usr/local/lib/libgmp.a
+
+Index: mpn/asm-defs.m4
+--- mpn/asm-defs.m4.orig
 mpn/asm-defs.m4
+@@ -1051,7 +1051,7 @@ dnl  Normally PIC is defined (or not) by libtool, but 
+ dnl  systems which are always PIC.  PIC_ALWAYS established in config.m4
+ dnl  identifies these for us.
+ 
+-ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
++ifelse(PIC_ALWAYS,`yes',`define(`PIC')')
+ 
+ 
+ dnl  Various possible defines passed from the Makefile that are to be tested



Re: [macppc / lld] devel/gmp text relocation

2021-09-09 Thread Charlene Wendling
On Thu, 9 Sep 2021 16:15:53 +0200
Christian Weisgerber  wrote:

> George Koehler:
> 
> > WRKSRC/mpn/asm-defs.m4:1054,
> > 
> > ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
> > 
> > Notice that `PIC_ALWAYS' is in quotes, so the macro PIC_ALWAYS is
> > not expanded.  This faulty check compares the literal string
> > "PIC_ALWAYS" with the literal string "yes"; these strings never
> > match, so this faulty check never defines PIC.  I don't fix this
> > faulty check, because it might affect other archs.
> 
> It appears that check is only used on powerpc*.  The only place I
> can find that defines PIC_ALWAYS is in GMP_ASM_POWERPC_PIC_ALWAYS,
> which is indeed only called on powerpc*.
> 
> So the fix might be as simple as repairing that ifelse?

Well, this fixes devel/xtensa-lx106-elf/gdb :

https://bin.charlenew.xyz/xtensa-lx106-elf-gdb-8.2.1p0.log



> -- 
> Christian "naddy" Weisgerber
> na...@mips.inka.de
> 



Re: [macppc / lld] devel/gmp text relocation

2021-09-09 Thread Christian Weisgerber
George Koehler:

> WRKSRC/mpn/asm-defs.m4:1054,
> 
> ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
> 
> Notice that `PIC_ALWAYS' is in quotes, so the macro PIC_ALWAYS is not
> expanded.  This faulty check compares the literal string "PIC_ALWAYS"
> with the literal string "yes"; these strings never match, so this
> faulty check never defines PIC.  I don't fix this faulty check,
> because it might affect other archs.

It appears that check is only used on powerpc*.  The only place I
can find that defines PIC_ALWAYS is in GMP_ASM_POWERPC_PIC_ALWAYS,
which is indeed only called on powerpc*.

So the fix might be as simple as repairing that ifelse?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de