Glib2 build problem

David DeHaven daved at bacomatic.org
Fri Sep 21 15:58:23 PDT 2007


Encountered a similar error trying to install glib2 on a system  
running Leopard (9A527):
ld: bc out of range (571728 max is +/-64K) from  
_g_atomic_int_exchange_and_add in .libs/gatomic.o to  
_g_atomic_int_exchange_and_add$stub in .libs/ 
libglib-2.0.0.1400.0.dylib in _g_atomic_int_exchange_and_add  
from .libs/gatomic.o

There's a bc instruction (or variant thereof, probably the "bne-")  
that's trying to jump further than 64K bytes from the PC, that's  
causing the linker error. This would have affected PowerPC builds only.

I poked around a short while and couldn't figure out what's causing  
the error. It could be a bug in the Leopard preview build of ld64...

I did notice the other functions in gatomic.c didn't have that  
problem, but they all have a sync instruction before the label, so I  
dropped a nop in front of the label in g_atomic_int_exchange_and_add  
(and then later g_atomic_int_add):
  __asm__ __volatile__ ("nop\n"
			".Lieaa%=:       lwarx   %0,0,%3\n"

Which compiles to:
	.align 2
	.p2align 4,,15
	.globl _g_atomic_int_exchange_and_add
_g_atomic_int_exchange_and_add:
	nop
.Lieaa17:       lwarx   r2,0,r3
         add     r0,r2,r4
         stwcx.  r0,0,r3
         bne-    .Lieaa17
	mr r3,r2
	blr

And things are building fine now, though wholly untested.

Note the only difference in the assembly output is the nop between the  
global and the local label (and the tab before the .Lieaa17 label,  
which doesn't make any difference):
_g_atomic_int_exchange_and_add:
	.Lieaa17:       lwarx   r2,0,r3

Otherwise they're the same. This really looks to me like a bug in ld64.

Here's a patch:
--- old/glib-2.14.0/glib/gatomic.c	2007-09-21 15:32:52.000000000 -0700
+++ new/glib-2.14.0/glib/gatomic.c	2007-09-21 15:32:33.000000000 -0700
@@ -276,7 +276,8 @@ g_atomic_int_exchange_and_add (volatile
  			       gint           val)
  {
    gint result, temp;
-  __asm__ __volatile__ (".Lieaa%=:       lwarx   %0,0,%3\n"
+  __asm__ __volatile__ ("nop\n"
+			".Lieaa%=:       lwarx   %0,0,%3\n"
  			"         add     %1,%0,%4\n"
  			"         stwcx.  %1,0,%3\n"
  			"         bne-    .Lieaa%="
@@ -292,7 +293,8 @@ g_atomic_int_add (volatile gint *atomic,
  		  gint           val)
  {
    gint result, temp;
-  __asm__ __volatile__ (".Lia%=:       lwarx   %0,0,%3\n"
+  __asm__ __volatile__ ("nop\n"
+			".Lia%=:       lwarx   %0,0,%3\n"
  			"         add     %1,%0,%4\n"
  			"         stwcx.  %1,0,%3\n"
  			"         bne-    .Lia%="




More information about the macports-users mailing list