Home » Language IDEs » C / C++ IDE (CDT) » Hello World in Assembly in Eclipse CDT: "make all" terminated with exit code 2(make: *** [subdir.mk:17: hello.o] Error 1)
Hello World in Assembly in Eclipse CDT: "make all" terminated with exit code 2 [message #1834251] |
Thu, 05 November 2020 19:23 |
Tom KPB Messages: 18 Registered: November 2020 |
Junior Member |
|
|
In Eclipse CDT, I created an Assembly Project and Source File:
File > New > Project > C++ Project
Empty Project, Linux GCC
Project Name: helloAsm
Next>
Debug and Release > Finish
Project > Properties > C/C++ Build > Settings
GCC Assembler>
Command: as
Commandline Patterns:
${COMMAND} ${FLAGS} -g --gstabs ${OUTPUT_FLAG} ${OUTPUT_PREFIX}
${OUTPUT} ${INPUTS}
Apply and Close
File > New > Source File
Source Folder: helloAsm
Source File: hello.S
Finish
hello.S:
.section .data
message: .string "Hello World!\n"
.section .text
# this directive allows the linker to see the "main" label
# which is our entry point
.globl main
# this directive allows the eclipse gdb to see a function called "main"
.func main
main:
mov $4, %eax
mov $1, %ebx
mov $message, %ecx
mov $14, %edx
int $0x80
mov $0, %eax
Project > Build Project
Error..
Console:
"make all" terminated with exit code 2. Build might be incomplete.
Build Failed. 1 error, 0 warnings.
Problems:
make: *** [subdir.mk:17: hello.o] Error 1
Any help?
[Updated on: Sat, 07 November 2020 03:49] Report message to a moderator
|
|
| | | | | | | | |
Re: Assembly: Build Error: 'Hello World' [message #1834316 is a reply to message #1834314] |
Sat, 07 November 2020 06:03 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
The error messages appear to be:
- make all" terminated with exit code 2. Build might be incomplete.
- make: *** [subdir.mk:17: hello.o] Error 1
As I said before, these don't really say anything other than make detected an error.
IOW: "Error! I quit!"
There are messages preceding them that give the real problem.
Your original post had an actual error message but you deleted it.
See the link with the example.
There should be a line similar to "gcc error:" or whatever in the build log.
What is it?
Update
FWIW:
I created a C++ Managed Build using your hello.S file.
It assembled and linked and I was able to run it.
I had to add a language mapping for assembly files to get it to edit.
Project --> Properties --> C/C++ General --> Language Mappings
Here's the build log
01:28:12 **** Build of configuration Debug for project ASMHello ****
make all
Building file: ../hello.S
Invoking: GCC Assembler
as -o "hello.o" "../hello.S"
Finished building: ../hello.S
Building target: ASMHello
Invoking: GCC C++ Linker
g++ -o "ASMHello" ./hello.o
Finished building target: ASMHello
01:28:14 Build Finished. 0 errors, 0 warnings. (took 2s.67ms)
Line 17 of my subdir.mk is:
The entire target and recipe is:
%.o: ../%.S
@echo 'Building file: $<'
@echo 'Invoking: GCC Assembler'
as -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
See https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html for $@ and $<
Should result in:
as -o <project name> ../hello.S
The only difference that I see is you have added -g --gstabs which shouldn't matter.
There seems to be something wrong occurring during the assembly in your installation
assuming that's what the make: *** [subdir.mk:17: hello.o] Error 1 is referring to.
Can't say what it is without seeing the error message(s).
Maybe you should just post the build log instead of going round and round about error messages.
[Updated on: Sat, 07 November 2020 07:02] Report message to a moderator
|
|
|
Re: Assembly: Build Error: 'Hello World' [message #1834318 is a reply to message #1834316] |
Sat, 07 November 2020 06:42 |
Tom KPB Messages: 18 Registered: November 2020 |
Junior Member |
|
|
Hello David:
(A) Build Log:
01:55:12 **** Incremental Build of configuration Debug for project firstASM ****
make all
Building file: ../hello.S
Invoking: GCC Assembler
as -g --gstabs -o "hello.o" "../hello.S"
as: unrecognized option '--gstabs'
make: *** [subdir.mk:17: hello.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
01:55:12 Build Failed. 1 errors, 0 warnings. (took 513ms)
-----------
(B) I removed '-g -gstabs'. Then, compiled, and I got this error log:
2:50:09 **** Incremental Build of configuration Debug for project firstASM ****
make all
Building file: ../hello.S
Invoking: GCC Assembler
as -o "hello.o" "../hello.S"
Assembler messages:
Error: can't open -o for reading: No such file or directory
-o: Error: can't open hello.o for reading: No such file or directory
make: *** [subdir.mk:17: hello.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
02:50:10 Build Failed. 2 errors, 0 warnings. (took 646ms)
[Updated on: Sat, 07 November 2020 07:57] Report message to a moderator
|
|
| | |
Re: Assembly: Build Error: 'Hello World' [message #1834323 is a reply to message #1834321] |
Sat, 07 November 2020 08:40 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
That's odd:
as with -g --gstabs works for me.
These are the real error messages:
Error: can't open -o for reading: No such file or directory -o:
Error: can't open hello.o for reading: No such file or directory
as is trying to open -o as an input file instead of regarding it as an option flag.
That would also mean it thinks hello.o is an input file.
I have no idea what would cause that.
Are you sure you are running the GNU assembler?
What happens when you try to run the command from a command line?
Add option --version and see what you get.
What OS are you using?
If linux (or Windows under cygwin), change the command for the assembler to "which as".
Should tell you where the executable for it is.
I don't really care but is it where you think it should be?
Try not to completely change posts by editing.
You will make things confusing for anyone else trying to follow along.
I only pointed to an edit because you posted while I was editing and I didn't want to repeat it.
This also applies to places like stackoverflow where you completely changed the original question.
Any answers to the original wouldn't make any sense to anyone reading only the changed version.
[Updated on: Sat, 07 November 2020 09:36] Report message to a moderator
|
|
| | | |
Re: Assembly: Build Error: 'Hello World' [message #1834331 is a reply to message #1834326] |
Sat, 07 November 2020 16:02 |
Tom KPB Messages: 18 Registered: November 2020 |
Junior Member |
|
|
Thanks Tauno Voipio:
(1) Debian Release:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
(2) 64 bit Architecture
$ uname -a
Linux debian 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux
(3) Assembly path
(4) the CDT 'Hello World' C source (not C++), and compile it using the command line, with assembly listing:
$ ls
hello.c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
$ gcc -c -Wa,-ahlms=hello.lst hello.c
$ ls
hello.c hello.lst hello.o
$ gcc -o hello -Wl,-Map=hello.map hello.o
$ ls
hello hello.c hello.lst hello.map hello.o
$ ./hello
Hello, World!
(5) _strace ./hello
$ _strace ./hello
_arguments:comparguments:325: can only be called from completion function
Sir: Can you please guide me, how to call from completion function?
[Updated on: Sat, 07 November 2020 17:31] Report message to a moderator
|
|
| | | |
Re: Assembly: Build Error: 'Hello World' [message #1834337 is a reply to message #1834334] |
Sat, 07 November 2020 23:47 |
Tom KPB Messages: 18 Registered: November 2020 |
Junior Member |
|
|
Sir (Tauno Voipio):
(1) Your advice is well taken:
Quote:My recommendation is to not attempt to by-pass the C library, and use the assembly listing as a starting point for assembly coding.
Besides, I have never needed to code in assembly for Linux, though I have written some megabytes of assembly code in over 50 years. Well written C is a mighty good super-assembly code.
My dream is to become a C/Linux programmer. So, I am trying to learn basics of Assembly.
Hats off & I salute you for your expertise, experience, and your ability to explain in very simple steps
Giving below, details of: hello.lst, hello.map, and strace ./hello:
(2) hello.lst
GAS LISTING /tmp/cc73Zy6P.s page 1
1 .file "hello.c"
2 .text
3 .section .rodata
4 .LC0:
5 0000 48656C6C .string "Hello, World!"
5 6F2C2057
5 6F726C64
5 2100
6 .text
7 .globl main
8 .type main, @function
9 main:
10 .LFB0:
11 .cfi_startproc
12 0000 55 pushq %rbp
13 .cfi_def_cfa_offset 16
14 .cfi_offset 6, -16
15 0001 4889E5 movq %rsp, %rbp
16 .cfi_def_cfa_register 6
17 0004 488D3D00 leaq .LC0(%rip), %rdi
17 000000
18 000b E8000000 call puts@PLT
18 00
19 0010 B8000000 movl $0, %eax
19 00
20 0015 5D popq %rbp
21 .cfi_def_cfa 7, 8
22 0016 C3 ret
23 .cfi_endproc
24 .LFE0:
25 .size main, .-main
26 .ident "GCC: (Debian 8.3.0-6) 8.3.0"
27 .section .note.GNU-stack,"",@progbits
^LGAS LISTING /tmp/cc73Zy6P.s page 2
DEFINED SYMBOLS
*ABS*:0000000000000000 hello.c
/tmp/cc73Zy6P.s:9 .text:0000000000000000 main
UNDEFINED SYMBOLS
_GLOBAL_OFFSET_TABLE_
puts
(3) hello.map:
rchive member included to satisfy reference by file (symbol)
//usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-l$
Discarded input sections
.note.GNU-stack
0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.note.GNU-stack
0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.note.GNU-stack
0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.note.GNU-stack
0x0000000000000000 0x0 hello.o
.note.GNU-stack
0x0000000000000000 0x0 //usr/lib/x86_64-linux-gnu/libc_n$
.note.GNU-stack
0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
Memory Configuration
Name Origin Length Attributes
*default* 0x0000000000000000 0xffffffffffffffff
Linker script and memory map
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o
LOAD hello.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libc.so
START GROUP
LOAD //lib/x86_64-linux-gnu/libc.so.6
LOAD //usr/lib/x86_64-linux-gnu/libc_nonshared.a
LOAD //lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o
[!provide] PROVIDE (__executable_start =$
0x00000000000002a8 . = (SEGMENT_START ("text-seg$
.interp 0x00000000000002a8 0x1c
*(.interp)
.interp 0x00000000000002a8 0x1c /usr/lib/gcc/x86_64-linux-gnu/8/.$
.note.ABI-tag 0x00000000000002c4 0x20
.note.ABI-tag 0x00000000000002c4 0x20 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.note.gnu.build-id
0x00000000000002e4 0x24
*(.note.gnu.build-id)
.note.gnu.build-id
0x00000000000002e4 0x24 /usr/lib/gcc/x86_64-linux-gnu/8/.$
hash
*(.hash)
.gnu.hash 0x0000000000000308 0x24
*(.gnu.hash)
.gnu.hash 0x0000000000000308 0x24 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.dynsym 0x0000000000000330 0xa8
*(.dynsym)
.dynsym 0x0000000000000330 0xa8 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.dynstr 0x00000000000003d8 0x82
*(.dynstr)
.dynstr 0x00000000000003d8 0x82 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.gnu.version 0x000000000000045a 0xe
*(.gnu.version)
.gnu.version 0x000000000000045a 0xe /usr/lib/gcc/x86_64-linux-gnu/8/.$
.gnu.version_d 0x0000000000000468 0x0
*(.gnu.version_d)
.gnu.version_d
0x0000000000000468 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.gnu.version_r 0x0000000000000468 0x20
*(.gnu.version_r)
.gnu.version_r
0x0000000000000468 0x20 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.rela.dyn 0x0000000000000488 0xc0
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
.rela.text 0x0000000000000488 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
.rela.data.rel.ro
0x0000000000000488 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.rela.data.rel.local
0x0000000000000488 0x18 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
.rela.got 0x00000000000004a0 0x78 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
.rela.bss 0x0000000000000518 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
.rela.ifunc 0x0000000000000518 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.rela.fini_array
0x0000000000000518 0x18 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.rela.init_array
0x0000000000000530 0x18 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.rela.plt 0x0000000000000548 0x18
*(.rela.plt)
.rela.plt 0x0000000000000548 0x18 /usr/lib/gcc/x86_64-linux-gnu/8/.$
[!provide] PROVIDE (__rela_iplt_start = $
*(.rela.iplt)
[!provide] PROVIDE (__rela_iplt_end = .)
0x0000000000001000 . = ALIGN (CONSTANT (MAXPAGES$
.init 0x0000000000001000 0x17
*(SORT_NONE(.init))
.init 0x0000000000001000 0x12 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000001000 _init
.init 0x0000000000001012 0x5 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.plt 0x0000000000001020 0x20
*(.plt)
.plt 0x0000000000001020 0x20 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000001030 puts@@GLIBC_2.2.5
*(.iplt)
.plt.got 0x0000000000001040 0x8
*(.plt.got)
.plt.got 0x0000000000001040 0x8 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000001040 __cxa_finalize@@GLIBC_2.2.5
.plt.sec
*(.plt.sec)
.text 0x0000000000001050 0x161
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
.text 0x0000000000001050 0x2b /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000001050 _start
.text 0x000000000000107b 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*fill* 0x000000000000107b 0x5
.text 0x0000000000001080 0xb5 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.text 0x0000000000001135 0x17 hello.o
0x0000000000001135 main
*fill* 0x000000000000114c 0x4
.text 0x0000000000001150 0x61 //usr/lib/x86_64-linux-gnu/libc_n$
0x0000000000001150 __libc_csu_init
0x00000000000011b0 __libc_csu_fini
.text 0x00000000000011b1 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.text 0x00000000000011b1 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.gnu.warning)
.fini 0x00000000000011b4 0x9
*(SORT_NONE(.fini))
.fini 0x00000000000011b4 0x4 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x00000000000011b4 _fini
.fini 0x00000000000011b8 0x5 /usr/lib/gcc/x86_64-linux-gnu/8/.$
[!provide] PROVIDE (__etext = .)
[!provide] PROVIDE (_etext = .)
[!provide] PROVIDE (etext = .)
0x0000000000002000 . = ALIGN (CONSTANT (MAXPAGES$
0x0000000000002000 . = SEGMENT_START ("rodata-se$
.rodata 0x0000000000002000 0x12
*(.rodata .rodata.* .gnu.linkonce.r.*)
.rodata.cst4 0x0000000000002000 0x4 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000002000 _IO_stdin_used
.rodata 0x0000000000002004 0xe hello.o
.rodata1
*(.rodata1)
.eh_frame_hdr 0x0000000000002014 0x3c
*(.eh_frame_hdr)
.eh_frame_hdr 0x0000000000002014 0x3c /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000002014 __GNU_EH_FRAME_HDR
*(.eh_frame_entry .eh_frame_entry.*)
.eh_frame 0x0000000000002050 0x108
*(.eh_frame)
.eh_frame 0x0000000000002050 0x30 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x2c (size before relaxing)
*fill* 0x0000000000002080 0x0
.eh_frame 0x0000000000002080 0x40 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.eh_frame 0x00000000000020c0 0x18 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x30 (size before relaxing)
.eh_frame 0x00000000000020d8 0x20 hello.o
0x38 (size before relaxing)
.eh_frame 0x00000000000020f8 0x5c //usr/lib/x86_64-linux-gnu/libc_n$
0x78 (size before relaxing)
.eh_frame 0x0000000000002154 0x4 /usr/lib/gcc/x86_64-linux-gnu/8/c$
*(.eh_frame.*)
.gcc_except_table
*(.gcc_except_table .gcc_except_table.*)
.gnu_extab
*(.gnu_extab*)
.exception_ranges
*(.exception_ranges .exception_ranges*)
0x0000000000003de8 . = DATA_SEGMENT_ALIGN (CONST$
.eh_frame
*(.eh_frame)
*(.eh_frame.*)
.gnu_extab
*(.gnu_extab)
.gcc_except_table
*(.gcc_except_table .gcc_except_table.*)
.exception_ranges
*(.exception_ranges .exception_ranges*)
.tdata 0x0000000000003de8 0x0
[!provide] PROVIDE (__tdata_start = .)
*(.tdata .tdata.* .gnu.linkonce.td.*)
.tbss
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
.preinit_array 0x0000000000003de8 0x0
[!provide] PROVIDE (__preinit_array_star$
*(.preinit_array)
[!provide] PROVIDE (__preinit_array_end $
.init_array 0x0000000000003de8 0x8
0x0000000000003de8 PROVIDE (__init_array_start =$
*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))
*(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .cto$
.init_array 0x0000000000003de8 0x8 /usr/lib/gcc/x86_64-linux-gnu/8/c$
0x0000000000003df0 PROVIDE (__init_array_end = .)
.fini_array 0x0000000000003df0 0x8
[!provide] PROVIDE (__fini_array_start =$
*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))
*(.fini_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .dto$
.fini_array 0x0000000000003df0 0x8 /usr/lib/gcc/x86_64-linux-gnu/8/c$
[!provide] PROVIDE (__fini_array_end = .)
*(.fini_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .dto$
.fini_array 0x0000000000003df0 0x8 /usr/lib/gcc/x86_64-linux-gnu/8/c$
[!provide] PROVIDE (__fini_array_end = .)
.ctors
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT_BY_NAME(.ctors.*))
*(.ctors)
.dtors
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT_BY_NAME(.dtors.*))
*(.dtors)
.jcr
*(.jcr)
.data.rel.ro 0x0000000000003df8 0x0
*(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*)
*(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
.data.rel.ro 0x0000000000003df8 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.dynamic 0x0000000000003df8 0x1e0
*(.dynamic)
.dynamic 0x0000000000003df8 0x1e0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000003df8 _DYNAMIC
.got 0x0000000000003fd8 0x28
*(.got)
.got 0x0000000000003fd8 0x28 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.igot)
0x0000000000004fe8 . = DATA_SEGMENT_RELRO_END (.$
.got.plt 0x0000000000004000 0x20
*(.got.plt)
.got.plt 0x0000000000004000 0x20 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000004000 _GLOBAL_OFFSET_TABLE_
*(.igot.plt)
.data 0x0000000000004020 0x10
*(.data .data.* .gnu.linkonce.d.*)
.data 0x0000000000004020 0x4 /usr/lib/gcc/x86_64-linux-gnu/8/.$
0x0000000000004020 data_start
0x0000000000004020 __data_start
.data 0x0000000000004024 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.data 0x0000000000004024 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
*fill* 0x0000000000004024 0x4
.data.rel.local
0x0000000000004028 0x8 /usr/lib/gcc/x86_64-linux-gnu/8/c$
0x0000000000004028 __dso_handle
.data 0x0000000000004030 0x0 hello.o
.data 0x0000000000004030 0x0 //usr/lib/x86_64-linux-gnu/libc_n$
.data 0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.data 0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.tm_clone_table
0x0000000000004030 0x0
.tm_clone_table
0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.tm_clone_table
0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.data1
*(.data1)
0x0000000000004030 _edata = .
[!provide] PROVIDE (edata = .)
0x0000000000004030 . = .
0x0000000000004030 __bss_start = .
.bss 0x0000000000004030 0x8
*(.dynbss)
.dynbss 0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(.bss .bss.* .gnu.linkonce.b.*)
.bss 0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.bss 0x0000000000004030 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
.bss 0x0000000000004030 0x1 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.bss 0x0000000000004031 0x0 hello.o
.bss 0x0000000000004031 0x0 //usr/lib/x86_64-linux-gnu/libc_n$
.bss 0x0000000000004031 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.bss 0x0000000000004031 0x0 hello.o
.bss 0x0000000000004031 0x0 //usr/lib/x86_64-linux-gnu/libc_n$
.bss 0x0000000000004031 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/c$
.bss 0x0000000000004031 0x0 /usr/lib/gcc/x86_64-linux-gnu/8/.$
*(COMMON)
0x0000000000004038 . = ALIGN ((. != 0x0)?0x8:0x1)
*fill* 0x0000000000004031 0x7
.lbss
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
0x0000000000004038 . = ALIGN (0x8)
0x0000000000004038 . = SEGMENT_START ("ldata-seg$
.lrodata
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
.ldata 0x0000000000006038 0x0
*(.ldata .ldata.* .gnu.linkonce.l.*)
0x0000000000006038 . = ALIGN ((. != 0x0)?0x8:0x1)
0x0000000000006038 . = ALIGN (0x8)
0x0000000000006038 _end = .
[!provide] PROVIDE (end = .)
0x0000000000006038 . = DATA_SEGMENT_END (.)
.stab
*(.stab)
.stabstr
*(.stabstr)
.stab.excl
*(.stab.excl)
.stab.exclstr
*(.stab.exclstr)
.stab.index
*(.stab.index)
.stab.indexstr
*(.stab.indexstr)
.comment 0x0000000000000000 0x1c
*(.comment)
.comment 0x0000000000000000 0x1c /usr/lib/gcc/x86_64-linux-gnu/8/c$
0x1d (size before relaxing)
.comment 0x000000000000001c 0x1d hello.o
.comment 0x000000000000001c 0x1d /usr/lib/gcc/x86_64-linux-gnu/8/c$
.debug
*(.debug)
.line
*(.line)
.debug_srcinfo
*(.debug_srcinfo)
.debug_sfnames
*(.debug_sfnames)
*(.debug_aranges)
.debug_pubnames
*(.debug_pubnames)
.debug_info
*(.debug_info .gnu.linkonce.wi.*)
.debug_abbrev
*(.debug_abbrev)
.debug_line
*(.debug_line .debug_line.* .debug_line_end)
.debug_frame
*(.debug_frame)
.debug_str
*(.debug_str)
.debug_loc
*(.debug_loc)
.debug_macinfo
*(.debug_macinfo)
.debug_weaknames
*(.debug_weaknames)
.debug_funcnames
*(.debug_funcnames)
.debug_typenames
*(.debug_typenames)
.debug_varnames
*(.debug_varnames)
.debug_pubtypes
*(.debug_pubtypes)
.debug_ranges
*(.debug_ranges)
.debug_macro
*(.debug_macro)
.debug_addr
*(.debug_addr)
.gnu.attributes
*(.gnu.attributes)
/DISCARD/
*(.note.GNU-stack)
*(.gnu_debuglink)
*(.gnu.lto_*)
OUTPUT(hello elf64-x86-64)
(4) $ strace ./hello
execve("./hello", ["./hello"], 0x7ffc6675bf80 /* 46 vars */) = 0
brk(NULL) = 0x561532c86000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=85969, ...}) = 0
mmap(NULL, 85969, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f45e22f5000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260A\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1824496, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f45e22f3000
mmap(NULL, 1837056, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f45e2132000
mprotect(0x7f45e2154000, 1658880, PROT_NONE) = 0
mmap(0x7f45e2154000, 1343488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f45e2154000
mmap(0x7f45e229c000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16a000) = 0x7f45e229c000
mmap(0x7f45e22e9000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f45e22e9000
mmap(0x7f45e22ef000, 14336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f45e22ef000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f45e22f4500) = 0
mprotect(0x7f45e22e9000, 16384, PROT_READ) = 0
mprotect(0x561531329000, 4096, PROT_READ) = 0
mprotect(0x7f45e2331000, 4096, PROT_READ) = 0
munmap(0x7f45e22f5000, 85969) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
brk(NULL) = 0x561532c86000
brk(0x561532ca7000) = 0x561532ca7000
write(1, "Hello, World!\n", 14Hello, World!
) = 14
exit_group(0) = ?
+++ exited with 0 +++
[Updated on: Sun, 08 November 2020 03:52] Report message to a moderator
|
|
| | |
Re: Assembly: Build Error: 'Hello World' [message #1834405 is a reply to message #1834387] |
Mon, 09 November 2020 19:33 |
Tauno Voipio Messages: 742 Registered: August 2014 |
Senior Member |
|
|
The problem is *not* CDT, but you're comparing a different assembler to the GNU as used as a part of the GCC toolset.
Attached is a version of the 'Hello World', running under 64 bit Linux (Kubuntu 20.04LTS) and using GCC embedded assembler. There are plenty of assumptions which prevent it from being good for expanding to something larger, but it is written in assembler code and it does not use libc.
It is probably a dumb thing to publish it, but it does run.
-
Attachment: hello.c
(Size: 1.23KB, Downloaded 93 times)
--
Tauno Voipio
[Updated on: Mon, 09 November 2020 19:34] Report message to a moderator
|
|
|
Re: Assembly: Build Error: 'Hello World' [message #1834410 is a reply to message #1834405] |
Mon, 09 November 2020 23:01 |
Michael Petch Messages: 2 Registered: November 2020 |
Junior Member |
|
|
There are a few issues here. You are attempting to create a 64-bit executable. The first issue is that the assembly code you have created is NOT position independent code (PIC). This is because the instruction is not position independent. Ubuntu (I think as of 18.04+) changed the default for GCC to generate PIC code and position independent executables (PIE). Earlier versions of Ubuntu were the opposite and GCC defaulted to non-PIC and non-PIE. A similar change occurred on Debian builds over the last few years as well.
Your `main` function doesn't ret to the C startup code that called `main`. Alternatively you could call the exit system call.
GCC as a front end to the LD linker is trying to be helpful from its perspective. It think the problem is that at least one of the objects has non-position independent code (which is true) so it suggests to compile with the `-fpic` or `-fPIC` option. GCC doesn't know the object file in question was hand generated. It thinks it was compiled by GCC(or G++) and that the source file was compiled with the `-fno-pic` or `-fno-PIC` option, thus its fix is for you to try the opposite `-fpic` or `-fPIC`. These are not options that the GNU assembler (as) knows about, they are compile options.
The quick hack is to actually tell GCC to link with -no-pie (and note the linker option is -no-pie and NOT -fno-pie). I haven't used CDT so I'm not sure if there is an option where you can change this or a command line option you can modify to add it. One of the other people may know how to do that.
The better option though is to create assembly code that is PIC . One method is to use RIP relative addressing (the memory address is relative to the instruction pointer). That can be done using the syntax labelname(%rip). You can use this with the LEA (load effective Address) to get the RIP relative address of a label like this: . You'd do this rather than using MOV $labelname, %register . Here is the catch though `int $0x80` in 64-bit code only uses the lower 32-bits of a register! It is quite possible (and likely) the .data section is at an address that can't be represented in a 32-bit register!
This brings us to the biggest problem. You are using `int $0x80` to make system calls in 64-bit code. As noted above one big problem is that you can't use addresses that may fall outside the first 4 GiB of virtual address space. Not all kernels are built with compatibility support for `int $0x80` emulation in 64-bit code (WSL1/Ubuntu on Windows doesn't have such support and will seg fault!).
The real fix is to make your code position independent and stop using `int $0x80` in 64-bit code. You want to use the syscall instruction instead. One catch is that the registers used and the system call numbers are different than 32-bit code. A good place for the 64-bit Linux system calls is Ryan Chapman's blog at https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ .
A version of your code that does the `ret`, uses RIP relative addressing and uses the 64-bit system call interface would be as follows:.section .data
message: .string "Hello World!\n"
msg_len = .-message # length of message
.section .text
# this directive allows the linker to see the "main" label
# which is our entry point
.globl main
# this directive allows the eclipse gdb to see a function called "main"
.func main
main:
mov $msg_len, %edx # message length
lea message(%rip), %rsi # message to write (RIP relative addressing)
mov $1, %edi # file descriptor (stdout = 1)
mov %edi, %eax # system call number (sys_write = 1)
syscall # Note: syscall instruction overwrites
# RCX and R11 and can't be relied on
# after the syscall
ret # return back to C startup code and exit
[Updated on: Tue, 10 November 2020 02:16] Report message to a moderator
|
|
|
Re: Assembly: Build Error: 'Hello World' [message #1834417 is a reply to message #1834410] |
Tue, 10 November 2020 03:27 |
Tom KPB Messages: 18 Registered: November 2020 |
Junior Member |
|
|
Sir ( Michael Petch):
Thank you very much. It is the perfect solution!
In fact, you had already solved my problem on Stack Overflow where I am waiting for removing that [duplicate] tag, then your solution as a formal answer so that I can accept it. There, I have made a request to you, under comments.
I am very much thankful to Tauno Voipio, David Vavra, and Ed Willink aslo, for their efforts in helping me to solve the issue.
I may consolidate the solution so that it can be useful for others also.
I have another question, about makefile, which I will ask shortly..
[Updated on: Tue, 10 November 2020 03:52] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Sun Oct 06 22:33:52 GMT 2024
Powered by FUDForum. Page generated in 0.06628 seconds
|