Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASM MacOS PIC
Hi.
 
Recently I've got a task to build a project under MACOS. Struggling many differences, I finaly got to an end, and everything seems to work, but one issue bothers me.
 
The project has assembly (NASM) code like this:
 
SECTION .rodata align=16
 
ALIGN 16
const_w05: times 8 dw 5
 

SECTION .text
 
ALIGN16
_some_function_sse2:
...
pmullw      xmm1,   [rel const_w05]
...
ret
 
Now whe it comes to linking, I get the following error:
ld: absolute addressing (perhaps -mdynamic-no-pic) used in (_some_function_sse2) from ... not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs
 
So reading lot of information on this, I had nothing bug put the suggested option -read_only_relocs suppress. The project was built and worked.
 
But I'm afraid it isn't correct and may not work if the shared object loads in different memory location.
 
BTW: The project is a shared object (dynamic library).
 
PS2: Everything builds on LINUX with no such errors.
Posted 27-Mar-12 0:08am
Edited 27-Mar-12 18:19pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

But why use the rel prefix? Probably the constant data is relocatable and could therefor be moved around which would break the relative addressing. What happens if you remove it?
  Permalink  
Comments
MaxLovic at 27-Mar-12 10:43am
   
Guess I did it, but not sure. Will try it.
MaxLovic at 27-Mar-12 22:57pm
   
Yep, the same result when 'rel' is removed. Even tried DEFAULT ABS just to be sure.
E.F. Nijboer at 28-Mar-12 5:27am
   
Found a link explaining -mdynamic-no-pic and I gives more insight on what it means. Indirectly it explains the given error.
http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/lin/compiler_c/copts/common_options/option_mdynamic_no_pic.htm
MaxLovic at 5-Apr-12 5:56am
   
Hi,
I've prepared a test project that shows the issue.
Please take a look here:
http://www.box.com/s/9e8f0f0b3ed6bbf22534
E.F. Nijboer at 5-Apr-12 13:20pm
   
I think you might be interested in this link, explaining about the GOT (global offset table).
https://developer.apple.com/library/mac/#documentation/DeveloperTools/nasm/nasmdoc8.html#section-8.2
 
Found the link above here by the way:
https://developer.apple.com/library/mac/#documentation/DeveloperTools/nasm/nasmdoc6.html#section-6.6.2
 
MaxLovic at 28-Mar-12 10:25am
   
I don't set mdynamic-no-pic explicitly, I set -fPIC and -O3. Though mdynamic-no-pic is set by the compiler option -O3, but I even turned it off, and passed only -fPIC - no profit.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

What if you change your absolute address to relative address. ie: .\data\mdynamic-no-pic.jpg or something like that.
  Permalink  
Comments
MaxLovic at 28-Mar-12 10:27am
   
Not sure I understood your idea. You say instead of
pmullw xmm1, [rel const_w05]
I should write
pmullw xmm1, [.\rodata\const_w05]
right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 27 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100