Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIE disabled. Absolute addressing when asm programming with gcc on mac OS X

I wrote this code. I want to compile it by gcc on mac OS X. But it appear 'PIE disabled. Absolute addressing' when I run gcc.

I googled it, but I can't find solution. Please advise me.

hello.s

.data
hello: .string "Hello World!\n"

.text
.globl _main

_main:
    push %rbp
    mov %rsp, %rbp
    movabs $hello, %rdi
    call _printf
    leave
    ret

error

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in
code signed PIE, but used in _main from /var/folders/xs/4z9kr_n93111fhv9_j1dd9gw0000gn/T/ex2_64-369300.o. 
To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
like image 287
shrwea Avatar asked Sep 01 '14 18:09

shrwea


1 Answers

Looks like there are a couple solutions:

  1. Link with -Wl,-no_pie:
clang -o hello hello.s -Wl,-no_pie
  1. Don't use absolute addressing.
.data
hello: .string "Hello World!\n"

.text
.globl _main

_main:
    push %rbp
    mov %rsp, %rbp
    lea hello(%rip), %rdi
    mov $0, %rax
    call _printf
    leave
    ret

Then you can compile and run:

host % clang -o hello hello.s            
host % ./hello 
Hello World!

The bit about zeroing out al is mentioned in section 3.5.7 of System V Application Binary Interface. Here's the relevant excerpt:

When a function taking variable-arguments is called, %al must be set to the total num- ber of floating point parameters passed to the function in vector registers.

In your case this is zero. You are passing in zero floating point parameters.

like image 196
Chris Avatar answered Oct 19 '22 09:10

Chris