[Flac-dev] Assembly on Mac OS needs to be relocatable

Matthew Sachs matthewg at zevils.com
Sat Jan 5 20:37:27 PST 2008


I'm trying to port flac 1.2.1 to OS X (I'm taking over maintainership  
of the Fink package), and I'm running into some problems with  
bitreader_asm.nasm.  After adding the following to nasm.h:

+%elifdef OBJ_FORMAT_macho
+	%define FLAC__PUBLIC_NEEDS_UNDERSCORE
+	%idefine code_section section .text
+	%idefine data_section section .data
+	%idefine bss_section  section .bss

I can get it compiling, but when it tries to link the libFLAC dylib,  
it complains:

ld: warning codegen in  
FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap.c1_loop (offset  
0x0000003A) prevents image from loading in dyld shared cache
ld: warning codegen in  
FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap.c1_next2 (offset  
0x00000012) prevents image from loading in dyld shared cache
ld: warning codegen in  
FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap.c2_next4 (offset  
0x00000015) prevents image from loading in dyld shared cache
ld: absolute addressing (perhaps -mdynamic-no-pic) used in  
FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap.c1_loop  
from .libs/libFLAC.lax/libFLAC-asm.a/bitreader_asm.o not allowed in  
slidable image

Mach-O shared libraries must be relocatable (-mdynamic-no-pic is a GCC  
flag for Darwin that makes it generate code where only the external  
references are relocatable, that's why the error message mentions that.)

I don't really know assembly, but based on <http://www.zathras.de/angelweb/blog-intel-assembler-on-mac-os-x.htm 
 >, I tried the following fix:


In c1_loop:
  %ifdef FLAC__PUBLIC_NEEDS_UNDERSCORE
+%ifdef OBJ_FORMAT_macho
+	call .epilog
+.myAnchorPoint:
+	lea	edi, [ebx + .myAnchorPoint + _FLAC__crc16_table]
+%else
  	mov	edi, _FLAC__crc16_table
+%endif
  %else
  	mov	edi, FLAC__crc16_table
  %endif

And then right before the end of the entire function:
  	ret

+%ifdef OBJ_FORMAT_macho+;; Needed for Mach-O PIC
+.epilog:
+	mov ebx, [esp]
+        ret
+%endif
+
  end


That wasn't very helpful:
bitreader_asm.nasm:144: error: beroset-p-650-invalid effective address
bitreader_asm.nasm:577: warning: label alone on a line without a colon  
might be in error

Does anyone have any other suggestions?

Thanks,
Matthew

-- 
Matthew Sachs <matthewg at zevils.com>
FreeNode IRC: msachs
http://zevils.com/



More information about the Flac-dev mailing list