Home > other >  How to put this simple assembly program compile and run successfully
How to put this simple assembly program compile and run successfully

Time:09-22

WSL Ubuntu18.04
GCC version 7.4.0 (Ubuntu ubuntu1 ~ 18.04.1 7.4.0-1)

. Section. Rodata 
MSG:
The ASCII "Hello, world. \ n"

. Section. The text
. Globl main
Main:
Movl $4, % eax
Movl $1, % ebx
Movl $MSG, % ecx
Movl $14, % edx
Int $0 x80

Movl $1, % eax
Movl $0, % ebx
Int $0 x80

1. Do not add any option, it is such a
 
$GCC hello. S
The/usr/bin/ld:/TMP/ccjICv40. O: relocation R_X86_64_32 against `. Data 'can not be, informs the when making a PIE object; Recompile with -fpic
The/usr/bin/ld: final link failed: Nonrepresentable section on the output
Collect2: error: ld returned 1 exit status


2. After add - no - pie option is
 
GCC - no - pie hello. S
Wj @ wj: ~/study/asm $./a.out
Segmentation fault (core dumped)


But clearly this is a simple program, there will be no period of wrong!

I write for school assembly, how is it so hard

CodePudding user response:

Hello, you succeeded? I also encountered this problem, but can't solve

CodePudding user response:

This is the assembly program, do not use GCC, as in
  • Related