Cannot change name of function in SASM












0















I want to have a function _say_hi() in SASM, but it won't link in my C program:



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


These are my questions



1) Can I run the assembly code if I change the function name? Because when I hit Run, it says:



[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


Then when I try to link it with my C program:



#include <stdio.h>

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


I get:



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









share|improve this question























  • extern void say_hi(void);. How do you assemble?

    – Antti Haapala
    Nov 26 '18 at 3:22











  • SASM is not an assembler. NASM is.

    – Antti Haapala
    Nov 26 '18 at 3:23






  • 1





    Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

    – Antti Haapala
    Nov 26 '18 at 3:25











  • You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

    – Peter Cordes
    Nov 26 '18 at 3:30











  • @PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

    – JorgeeFG
    Nov 26 '18 at 3:31


















0















I want to have a function _say_hi() in SASM, but it won't link in my C program:



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


These are my questions



1) Can I run the assembly code if I change the function name? Because when I hit Run, it says:



[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


Then when I try to link it with my C program:



#include <stdio.h>

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


I get:



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









share|improve this question























  • extern void say_hi(void);. How do you assemble?

    – Antti Haapala
    Nov 26 '18 at 3:22











  • SASM is not an assembler. NASM is.

    – Antti Haapala
    Nov 26 '18 at 3:23






  • 1





    Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

    – Antti Haapala
    Nov 26 '18 at 3:25











  • You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

    – Peter Cordes
    Nov 26 '18 at 3:30











  • @PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

    – JorgeeFG
    Nov 26 '18 at 3:31
















0












0








0








I want to have a function _say_hi() in SASM, but it won't link in my C program:



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


These are my questions



1) Can I run the assembly code if I change the function name? Because when I hit Run, it says:



[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


Then when I try to link it with my C program:



#include <stdio.h>

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


I get:



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









share|improve this question














I want to have a function _say_hi() in SASM, but it won't link in my C program:



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


These are my questions



1) Can I run the assembly code if I change the function name? Because when I hit Run, it says:



[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


Then when I try to link it with my C program:



#include <stdio.h>

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


I get:



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






c gcc assembly sasm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 3:12









JorgeeFGJorgeeFG

2,55773562




2,55773562













  • extern void say_hi(void);. How do you assemble?

    – Antti Haapala
    Nov 26 '18 at 3:22











  • SASM is not an assembler. NASM is.

    – Antti Haapala
    Nov 26 '18 at 3:23






  • 1





    Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

    – Antti Haapala
    Nov 26 '18 at 3:25











  • You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

    – Peter Cordes
    Nov 26 '18 at 3:30











  • @PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

    – JorgeeFG
    Nov 26 '18 at 3:31





















  • extern void say_hi(void);. How do you assemble?

    – Antti Haapala
    Nov 26 '18 at 3:22











  • SASM is not an assembler. NASM is.

    – Antti Haapala
    Nov 26 '18 at 3:23






  • 1





    Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

    – Antti Haapala
    Nov 26 '18 at 3:25











  • You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

    – Peter Cordes
    Nov 26 '18 at 3:30











  • @PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

    – JorgeeFG
    Nov 26 '18 at 3:31



















extern void say_hi(void);. How do you assemble?

– Antti Haapala
Nov 26 '18 at 3:22





extern void say_hi(void);. How do you assemble?

– Antti Haapala
Nov 26 '18 at 3:22













SASM is not an assembler. NASM is.

– Antti Haapala
Nov 26 '18 at 3:23





SASM is not an assembler. NASM is.

– Antti Haapala
Nov 26 '18 at 3:23




1




1





Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

– Antti Haapala
Nov 26 '18 at 3:25





Also you're building 64-bit exe; can't really use int 0x80 - stackoverflow.com/questions/46087730/…

– Antti Haapala
Nov 26 '18 at 3:25













You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

– Peter Cordes
Nov 26 '18 at 3:30





You're doing a bunch of stuff wrong- build a 32-bit non-PIE executable (instead of 64-bit PIE, which is causing the relocation problems), and don't prefix symbol names with _. Linux/ELF uses C symbol names directly in asm. And you're declaring say_hi inside main, which is weird.

– Peter Cordes
Nov 26 '18 at 3:30













@PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

– JorgeeFG
Nov 26 '18 at 3:31







@PeterCordes I was just following a tutorial. I wish to use SIMD instructions, so I guess I should set SASM to work with 64 bits? Could you help me?

– JorgeeFG
Nov 26 '18 at 3:31














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474329%2fcannot-change-name-of-function-in-sasm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474329%2fcannot-change-name-of-function-in-sasm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista