Click here to Skip to main content
11,932,048 members (54,578 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASM 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 27-Mar-12 0:08am
Edited 27-Mar-12 18: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 27-Mar-12 10:43am
Guess I did it, but not sure. Will try it.
MaxLovic 27-Mar-12 22:57pm
Yep, the same result when 'rel' is removed. Even tried DEFAULT ABS just to be sure.
E.F. Nijboer 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 5-Apr-12 5:56am
I've prepared a test project that shows the issue.
Please take a look here:
E.F. Nijboer 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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.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