Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Tom KPB is currently offline Tom KPBFriend
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 #1834284 is a reply to message #1834251] Fri, 06 November 2020 13:29 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
PIE means Position Independent Object
You are trying to mix position independent code with non-position independent code
or your target doesn't support it.

GCC enables PIE by default.
recompile your code using -fPIC is one solution

Read: https://gcc.gnu.org/onlinedocs/gcc-3.4.0/gcc/Link-Options.html#Link%20Options
scroll down to "-pie"

https://gcc.gnu.org/onlinedocs/gcc-3.4.0/gcc/Code-Gen-Options.html#Code%20Gen%20Options
scroll down to "-fpic" and "-fPIC"




Re: Assembly: Build Error: 'Hello World' [message #1834305 is a reply to message #1834284] Fri, 06 November 2020 22:32 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Thank you David:

I am totally new to this.

I read both the links, but NO idea how and where to use it.

I would appreciate, if you please guide me to do so.
Re: Assembly: Build Error: 'Hello World' [message #1834306 is a reply to message #1834305] Sat, 07 November 2020 00:08 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
What you are asking is how to use gcc.
That's off topic in this forum.
A fundamental assumption in Eclipse is you know how to use the external tools.

I understand your frustration.
How you solve this depends a lot on what you're trying to do.
You may be able to get away with adding "-no-pie" to your link and compile steps..
https://stackoverflow.com/q/47778099

This may help:
https://stackoverflow.com/a/5030518

You could also try Googling "creating position independent executable with gcc
Or similar
Re: Assembly: Build Error: 'Hello World' [message #1834309 is a reply to message #1834306] Sat, 07 November 2020 03:54 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Thanks David:

I edited the post

In fact, it is not PIE issue, it seems.

Rather, it has something to do with linking object file.
I could compile it easily in Debian. But, Eclipse CDT is giving problem..
Re: Assembly: Build Error: 'Hello World' [message #1834310 is a reply to message #1834309] Sat, 07 November 2020 04:20 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Your edit removed the error message but make is still failing.
make: *** [subdir.mk:17: hello.o] Error 1 usually means "can't find hello.o"
There likely was at least one message before this explaining the actual problem.
Possibly a compile error or bad command line option.
e.g., https://stackoverflow.com/questions/30222597/make-o-error-1

As it is, all we can say is make encountered a problem at line 17 in subdir.mk

Your original post had an error message explicitly naming PIE and suggesting the use of -fPIC
What happened?
Why did you delete it?

I saw your question at stackoverflow
https://stackoverflow.com/questions/64700515/assembly-in-eclipse-cdt-make-all-terminated-with-exit-code-2-build-might-be

You're spinning your wheels asking about generic error messages that say little beyond "Error! I quit!"



[Updated on: Sat, 07 November 2020 04:35]

Report message to a moderator

Re: Assembly: Build Error: 'Hello World' [message #1834311 is a reply to message #1834310] Sat, 07 November 2020 04:34 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
What I did was:

(1) Deleted the initial project.

(2) Instead of C, I made the new project in C++

(3) Instead of Cross GCC, I used Linux GCC.

Now, the errors reduced from 3 to 1.
Re: Assembly: Build Error: 'Hello World' [message #1834312 is a reply to message #1834311] Sat, 07 November 2020 04:36 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
But you aren't telling us what it is.
Re: Assembly: Build Error: 'Hello World' [message #1834314 is a reply to message #1834312] Sat, 07 November 2020 04:47 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Sir:

my post has:

(1) Every step that I followed

(2) Source code

(3) Error message

What else is required, may I know?
Re: Assembly: Build Error: 'Hello World' [message #1834316 is a reply to message #1834314] Sat, 07 November 2020 06:03 Go to previous messageGo to next message
David VavraFriend
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:
as  -o "$@" "$<"

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 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
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 #1834319 is a reply to message #1834318] Sat, 07 November 2020 07:04 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
I don't need your makefile.
I need to see your build log.
See my update.
https://www.eclipse.org/forums/index.php?t=msg&th=1105797&goto=1834316&#msg_1834316

[Updated on: Sat, 07 November 2020 07:05]

Report message to a moderator

Re: Assembly: Build Error: 'Hello World' [message #1834321 is a reply to message #1834319] Sat, 07 November 2020 07:58 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Sir:

I edited it to build log (above)
Re: Assembly: Build Error: 'Hello World' [message #1834323 is a reply to message #1834321] Sat, 07 November 2020 08:40 Go to previous messageGo to next message
David VavraFriend
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?

$ which as
/usr/bin/as


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 #1834326 is a reply to message #1834321] Sat, 07 November 2020 12:29 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Tom:

You are leaving out essential information:
- which operating system
- which processor

My guess is that you're attempting to produce raw assembly code for an Intel-based 32 bit Linux system without using the C library (libc).

This is actually off-topic for Eclipse CDT.

I'd like to suggest another path:

Take the CDT 'Hello World' C source (not C++), and compile it using the command line, with assembly listing:
gcc -c -Wa,-ahlms=hello.lst hello.c

Have a look at the generated assembly code in the listing.

Link the code into a run module:
gcc -o hello -Wl,-Map=hello.map hello.o

If everything went well, you should be able to run the code:
./hello

The file hello.map shows the code layout and library modules called in the final code.

There are plenty of things going behind scenes for running a Linux executable file. To see the system calls performed, run the code under strace:
strace ./hello



--

Tauno Voipio
Re: Assembly: Build Error: 'Hello World' [message #1834328 is a reply to message #1834323] Sat, 07 November 2020 15:27 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Sir:

(1)
$ which as
/usr/bin/as

(2) Using Debian 10 on Oracle VirtualBox

(3) You said above:
Quote:
I had to add a language mapping for assembly files to get it to edit.
Project --> Properties --> C/C++ General --> Language Mappings


Can you please let me know what you changed there?

[Updated on: Sat, 07 November 2020 15:29]

Report message to a moderator

Re: Assembly: Build Error: 'Hello World' [message #1834330 is a reply to message #1834328] Sat, 07 November 2020 16:01 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Executing which from the command line may not give the same result as when executed by Eclipse.
That was just to show you what to expect.

Again, change the as command in Eclipse

The language mapping simply causes the asm text editor to be used.

You need to verify that the GNU assembler is being used.

[Updated on: Sat, 07 November 2020 16:03]

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 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
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
 $ which as   
/usr/bin/as

(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 #1834332 is a reply to message #1834330] Sat, 07 November 2020 16:35 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Hello David:

(1) You need to verify that the GNU assembler is being used.

Project > Properties > C/C++ General > Paths and Symbols:
Assembly
C
C++

(2) Change the as command in Eclipse.
Sir: Can you please clarify, how to do this?
Re: Assembly: Build Error: 'Hello World' [message #1834334 is a reply to message #1834331] Sat, 07 November 2020 18:15 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Did you look at hello.lst and hello.map?

Did you run the strace to see how much has to be done besides the obvious in main()?

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.


--

Tauno Voipio
Re: Assembly: Build Error: 'Hello World' [message #1834335 is a reply to message #1834334] Sat, 07 November 2020 19:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7675
Registered: July 2009
Senior Member
Hi

Conversely once you understand how the generated assembler code relates to the source C code, you can write stylized C code that is much closer to assembler efficiency without all the hazards of assembler programming. And if you really need it, some compilers have inline assembler capabilities that enable special assembly level tweaks to be used as C code. This can be really good to wrap a low level device driver up as a C++ class.

Regards

Ed Willink
Re: Assembly: Build Error: 'Hello World' [message #1834337 is a reply to message #1834334] Sat, 07 November 2020 23:47 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
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 #1834348 is a reply to message #1834337] Sun, 08 November 2020 12:52 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
As you can see from the strace output, it is not a good idea to attempt to program around the libc startup in assembly code, you should need to do it all in the naked code.

For assembly code use in need, I suggest getting the GCC manual and reading the part of embedded assembly code. The manual is available from <https://gcc.gnu.org/onlinedocs/>. Match the version with the one you have.

You should also get the binutils (assembler, linker, tools) manuals from the GNU website, to understand what it going on.

Attached is an example of GCC embedded assembler use in ARM Cortex-M3 thread switcher code.


--

Tauno Voipio
Re: Assembly: Build Error: 'Hello World' [message #1834387 is a reply to message #1834348] Mon, 09 November 2020 14:01 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Sir: (Mr. Tauno Voipio):

Thanks for your responses.

I have all those required tools and latest versions.

It (NASM) is working very well in command line; problem is with Eclipse CDT.

Shall I post it again, in simplified way, to try to get some help?
Re: Assembly: Build Error: 'Hello World' [message #1834405 is a reply to message #1834387] Mon, 09 November 2020 19:33 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
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 Go to previous messageGo to next message
Michael Petch is currently offline Michael PetchFriend
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
mov $message, %ecx
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:
lea message(%rip), %rcx
. 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 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
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

Re: Assembly: Build Error: 'Hello World' [message #1834468 is a reply to message #1834405] Tue, 10 November 2020 19:59 Go to previous messageGo to next message
Michael Petch is currently offline Michael PetchFriend
Messages: 2
Registered: November 2020
Junior Member
Tauno Voipio wrote on Mon, 09 November 2020 19:33
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.

Your code is doing something that isn't really supported by function that use the naked attribute on x86 processors. There is a caveat in the GCC documentation that says:

Quote:
Only basic asm statements can safely be included in naked functions (see Basic Asm). While using extended asm or a mixture of basic asm and C code may appear to work, they cannot be depended upon to work reliably and are not supported.


Your code uses a mixture of basic asm and extended inline assembly (inline assembly with constraints). On an unrelated note if you pass the address of data through a register (one of your extended asm statements does so) you will need to add a memory clobber. Without it the compiler won't know your inline assembly needs the actual data that the pointer in the register point to. Without it, the compiler only knows that the pointer value will be used. There is an alternative to the memory clobber but it requires passing in a dummy memory constraint. The extended asm documentation has information on the memory clobber and some alternatives.
Re: Assembly: Build Error: 'Hello World' [message #1834479 is a reply to message #1834468] Wed, 11 November 2020 06:53 Go to previous message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Thank you. It seems that my coding brain was still in ARM mode.

I'm not sure about the memory clobber when the pointer is to a const entity.

Updated version, with both 32 bit and 64 bit run files and Makefile, is attached.
  • Attachment: hello.tgz
    (Size: 2.30KB, Downloaded 113 times)


--

Tauno Voipio
Previous Topic:How to use GTK+-3.0 or gtkmm library in Eclipse 2020-03
Next Topic:ROS + Eclipse Issues
Goto Forum:
  


Current Time: Sun Oct 06 22:33:52 GMT 2024

Powered by FUDForum. Page generated in 0.06628 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top