无法更改SASM中的功能名称

时间:2018-11-26 03:12:20

标签: c gcc assembly sasm

我想在SASM中有一个函数_say_hi(),但是它不会在我的C程序中链接:

SECTION .DATA
    hello:     db 'Hello world!',10
    helloLen:  equ $-hello

SECTION .TEXT
    GLOBAL _say_hi

_say_hi:
    mov eax,4            ; write()
    mov ebx,1            ; STDOUT
    mov ecx,hello
    mov edx,helloLen
    int 80h                 ; Interrupt
    ret                        ; Return control

这些是我的问题

1)如果更改函数名称,可以运行汇编代码吗?因为当我点击运行时,它说:

[00:10:21] Build started...
[00:10:21] Warning! Errors have occurred in the build:
/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib32/Scrt1.o: In function `_start':
(.text+0x28): undefined reference to `main'
collect2: error: ld returned 1 exit status

然后,当我尝试将其与我的C程序链接时:

#include <stdio.h>

int main(int argc, char *argv[]) {
    extern say_hi();
    say_hi();
}

我得到:

jorgee@jorgee-Aspire-5830TG:~/Desktop/Orga2$ gcc src/main.c asm/test.o -o main
src/main.c: In function ‘main’:
src/main.c:4:9: warning: type defaults to ‘int’ in declaration of ‘say_hi’ [-Wimplicit-int]
  extern say_hi();
         ^~~~~~
/usr/bin/ld: asm/test.o: relocation R_X86_64_32 against `.DATA' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

0 个答案:

没有答案