Why does `-fno-plt` not work when compiling/linking assembly?

I am interested in compiling / linking an assembly project whose shared library function calls bypass the PLT (use the GOT directly). I Tried using -fno-plt but the resulting library calls still go through the PLT.

Questions

I am wondering:

  1. Why does the -fno-plt argument not work when compiling assembly?
  2. Is there a way to compile assembly so that shared library function calls bypass the PLT?

Assembly PLT Bypass with -fno-plt NOT Working.

Using the simplest example:

    .global main
    .text
main:
    callq   exit

When compiled with:

gcc -fno-plt test0.S -o test0

Produces the following for main:

0000000000001139 <main>:
    1139:   e8 f2 fe ff ff          callq  1030 <exit@plt>
    113e:   66 90                   xchg   %ax,%ax

Which is calling exit through the PLT.

C PLT Bypass with -fno-plt Working

Alternatively the same code in C:

extern void exit(int);
int main() {
    exit(0);
}

Compiled with:

gcc -O2 -fno-plt  test1.c -o test1 

Gets the following for main:

0000000000001040 <main>:
    1040:   f3 0f 1e fa             endbr64 
    1044:   50                      push   %rax
    1045:   58                      pop    %rax
    1046:   31 ff                   xor    %edi,%edi
    1048:   48 83 ec 08             sub    $0x8,%rsp
    104c:   ff 15 96 2f 00 00       callq  *0x2f96(%rip)        # 3fe8 <exit@GLIBC_2.2.5>
    1052:   66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
    1059:   00 00 00 
    105c:   0f 1f 40 00             nopl   0x0(%rax)

Which correctly bypasses the PLT for the call to exit.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum