0

i tried many times to assemble and link my file code.s, assemble went successfully but linking always failing with the following error

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from code.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
final section layout:
    __TEXT/__text addr=0x100003FB3, size=0x00000005, fileOffset=0x00003FB3, type=1
    __TEXT/__unwind_info addr=0x100003FB8, size=0x00000048, fileOffset=0x00003FB8, type=22
    __DATA/__data addr=0x100004000, size=0x00000012, fileOffset=0x00004000, type=0
ld: 32-bit absolute address out of range (0x100004000 max is 4GB): from _main + 0x00000001 (0x100003FB3) to number (0x100004000) in '_main' from code.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

assemble using gcc -c code.s

linking using gcc code.o -o code

the file code.s contents

.data 
       number: .float 89.45
       sentence: .ascii "this is string"

.text 

.globl _main

_main:

      movl $number,%eax

any suggestions please on how to solve this issue

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Have you tried following the advice given in the error message and linking with `-Wl,-no_pie`? – fuz Feb 08 '22 at 09:16
  • i tried and get the same error – user16704820 Feb 08 '22 at 09:43
  • 1
    Ok. Try replacing `movl $number, %eax` with `leaq number(%rip), %rax`. – fuz Feb 08 '22 at 09:47
  • Near duplicate of [32-bit absolute addresses no longer allowed in x86-64 Linux?](https://stackoverflow.com/q/43367427). Probably is a duplicate of [How to load address of function or label into register](https://stackoverflow.com/q/57212012) even though that doesn't mention this MacOS error message. – Peter Cordes Feb 08 '22 at 09:52

0 Answers0