Click here to Skip to main content
11,797,355 members (80,949 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASM MacOS PIC

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
const_w05: times 8 dw 5

pmullw      xmm1,   [rel const_w05]

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 26-Mar-12 23:08pm
Edited 27-Mar-12 17:19pm
Rate this: bad
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?
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.
MaxLovic at 5-Apr-12 5:56am
I've prepared a test project that shows the issue.
Please take a look here:
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).

Found the link above here by the way:

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
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.
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]

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

  Print Answers RSS
0 CPallini 475
1 Maciej Los 370
2 OriginalGriff 363
3 Abhinav S 344
4 Andy Lanng 296
0 OriginalGriff 2,092
1 Maciej Los 1,760
2 KrunalRohit 1,436
3 CPallini 1,245
4 ppolymorphe 893

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 27 Mar 2012
Copyright © CodeProject, 1999-2015
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