Skip to content

-fno-plt disregarded when compiling *.zig #22254

@xBZZZZ

Description

@xBZZZZ

Zig Version

0.14.0-dev.2487+af89bb05d

Steps to Reproduce and Observed Behavior

  1. create file plt_test.c with content:
    int imported_function(void);
    int exported_function(void){
    return imported_function()+1;
    }
  2. run
    zig cc -target x86_64-linux-gnu -nostdlib -shared -Os -fno-plt -o plt_test_c.so plt_test.c
  3. run
    eu-objdump --disassemble plt_test_c.so
    it outputs
    plt_test_c.so: elf64-elf_x86_64
    
    Disassembly of section .text:
    
        1314:    50                       push    %rax
        1315:    ff 15 c5 10 00 00        callq   *0x10c5(%rip)              # 0x23e0
        131b:    ff c0                    inc     %eax
        131d:    59                       pop     %rcx
        131e:    c3                       retq
    no .plt section because -fno-plt
  4. create file plt_test.zig with content:
    extern fn imported_function() callconv(.C) i32;
    export fn exported_function() callconv(.C) i32{
    return imported_function()+1;
    }
  5. run
    zig cc -target x86_64-linux-gnu -nostdlib -shared -Os -fno-plt -o plt_test_zig.so plt_test.zig
  6. run
    eu-objdump --disassemble plt_test_zig.so
    it outputs
    plt_test_zig.so: elf64-elf_x86_64
    
    Disassembly of section .text:
    
        1314:    50                       push    %rax
        1315:    e8 16 00 00 00           callq   0x1330
        131a:    ff c0                    inc     %eax
        131c:    59                       pop     %rcx
        131d:    c3                       retq
    Disassembly of section .plt:
    
        1320:    ff 35 f2 10 00 00        pushq   0x10f2(%rip)               # 0x2418
        1326:    ff 25 f4 10 00 00        jmpq    *0x10f4(%rip)              # 0x2420
        132c:    0f 1f 40 00              nopl    0x0(%rax)
        1330:    ff 25 f2 10 00 00        jmpq    *0x10f2(%rip)              # 0x2428
        1336:    68 00 00 00 00           pushq   $0x0
        133b:    e9 e0 ff ff ff           jmpq    0x1320
    .plt section exists, -fno-plt disregarded

Expected Behavior

zig cc -target x86_64-linux-gnu -nostdlib -shared -Os -fno-plt -o plt_test_zig.so plt_test.zig
doesn't generate .plt section and
eu-objdump --disassemble plt_test_zig.so
outputs
plt_test_zig.so: elf64-elf_x86_64

Disassembly of section .text:

    1314:    50                       push    %rax
    1315:    ff 15 c5 10 00 00        callq   *0x10c5(%rip)              # 0x23e0
    131b:    ff c0                    inc     %eax
    131d:    59                       pop     %rcx
    131e:    c3                       retq

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions