Author Topic: Assembling an elf64 file on Windows  (Read 20034 times)

Offline eldiener

  • Jr. Member
  • *
  • Posts: 5
Assembling an elf64 file on Windows
« on: May 12, 2020, 01:37:18 AM »
The Embarcadero 64-bit bcc64 clang-based compiler generates elf64 object files on Windows. I am trying to assemble the elf64 assembler files in the Boost context library with the nasm compiler, using the '-t -f elf64' command line options. The Boost context elf64 assembly files which come closest for me to use are 'x86_64_sysv_elf_gas.S' files. These files have C++ style /* */ comments in them but nasm evdiently does not understand that these are comments and expects assembly code instead. I know that the clang compiler on Windows targeting gcc produces elf output, so it must be possible for assembly files to be in elf64 format on Windows. Are elf64 assembly files not supposed to have C++ style comments in them ?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Assembling an elf64 file on Windows
« Reply #1 on: May 12, 2020, 02:37:46 AM »
Hi eldiener,

Welcome to the forum.

Part pf your question is easy. No, Nasm does not accept /* */ style comments. Use a semicolon ";" - one per line. Sorry.

But I'm confused why you're using "-f elf64" on Windows. Usually, "elf" (executable and linkable format) would be for Linux, the BSDs, Unix, ect. You'd want "-f win64" for Windows. I'm not familiar with the tools you're using, so I could be wrong, but I doubt if "-f elf64" is what you want. What makes you think so?

Best,
Frank


Offline eldiener

  • Jr. Member
  • *
  • Posts: 5
Re: Assembling an elf64 file on Windows
« Reply #2 on: May 12, 2020, 03:01:20 PM »
Hi eldiener,

Welcome to the forum.

Part pf your question is easy. No, Nasm does not accept /* */ style comments. Use a semicolon ";" - one per line. Sorry.

But I'm confused why you're using "-f elf64" on Windows. Usually, "elf" (executable and linkable format) would be for Linux, the BSDs, Unix, ect. You'd want "-f win64" for Windows. I'm not familiar with the tools you're using, so I could be wrong, but I doubt if "-f elf64" is what you want. What makes you think so?

Best,
Frank

Talking to Embarcadero I was told that 'nasm -t -f elf64' was the assembly I should use and that the Embarcadero bcc64 64-bit compiler produces ELF object files on Windows. Embarcadero uses clang as their backend when compiling so this does not surprise me.

You explain that only the semi-colon is acceptable as a comment and yet the Boost context library uses /* */ multi-line comments for all their assembly files. I have queried the developer/maintainer of the Boost context library about this.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Assembling an elf64 file on Windows
« Reply #3 on: May 12, 2020, 09:12:01 PM »
Okay. I'm astonished that Windows runs ELF! We live and learn. Thanks!

Best,
Frank


Offline eldiener

  • Jr. Member
  • *
  • Posts: 5
Re: Assembling an elf64 file on Windows
« Reply #4 on: May 12, 2020, 09:25:23 PM »
Okay. I'm astonished that Windows runs ELF! We live and learn. Thanks!

Best,
Frank

Windows does not run ELF. the ELF object files become normal Windows exes and DLLs when linked by the Embarcadero 64-bit linker..

Offline eldiener

  • Jr. Member
  • *
  • Posts: 5
Re: Assembling an elf64 file on Windows
« Reply #5 on: May 12, 2020, 09:29:17 PM »
Hi eldiener,

Welcome to the forum.

Part pf your question is easy. No, Nasm does not accept /* */ style comments. Use a semicolon ";" - one per line. Sorry.

But I'm confused why you're using "-f elf64" on Windows. Usually, "elf" (executable and linkable format) would be for Linux, the BSDs, Unix, ect. You'd want "-f win64" for Windows. I'm not familiar with the tools you're using, so I could be wrong, but I doubt if "-f elf64" is what you want. What makes you think so?

Best,
Frank

Assembling ther same files with /* */ comments on Fedora 31 both gcc-9.3 and clang-9.0 have no problems with the comments. Should not NASM try to be compatrible with the native assemblers in regard to comments as it tries to be compatible in regard to assembly langUage syntax. Has anyone ever brought this up before ? If not I am a bit surprised.

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Assembling an elf64 file on Windows
« Reply #6 on: May 13, 2020, 01:23:07 AM »
Hi eldiener,

Welcome to the forum.

Part pf your question is easy. No, Nasm does not accept /* */ style comments. Use a semicolon ";" - one per line. Sorry.

But I'm confused why you're using "-f elf64" on Windows. Usually, "elf" (executable and linkable format) would be for Linux, the BSDs, Unix, ect. You'd want "-f win64" for Windows. I'm not familiar with the tools you're using, so I could be wrong, but I doubt if "-f elf64" is what you want. What makes you think so?

Best,
Frank

Assembling ther same files with /* */ comments on Fedora 31 both gcc-9.3 and clang-9.0 have no problems with the comments. Should not NASM try to be compatrible with the native assemblers in regard to comments as it tries to be compatible in regard to assembly langUage syntax. Has anyone ever brought this up before ? If not I am a bit surprised.

NASM *is* a native assembler. It follows Intel syntax. gas diverged from the original syntax.
gcc will not have problems with /*---*/ comments as gcc is a C compiler, and you are passing it standard C comments.
I don't know "clang", but from the name I assume that is also a C compiler, so same applies.

What is standard for one programming language does not have to be standard for others. Assembly language came before C, so by your reasoning, C standard must be wrong :)

My graphics card database: www.gpuzoo.com

Offline eldiener

  • Jr. Member
  • *
  • Posts: 5
Re: Assembling an elf64 file on Windows
« Reply #7 on: May 13, 2020, 04:39:51 PM »
Hi eldiener,

Welcome to the forum.

Part pf your question is easy. No, Nasm does not accept /* */ style comments. Use a semicolon ";" - one per line. Sorry.

But I'm confused why you're using "-f elf64" on Windows. Usually, "elf" (executable and linkable format) would be for Linux, the BSDs, Unix, ect. You'd want "-f win64" for Windows. I'm not familiar with the tools you're using, so I could be wrong, but I doubt if "-f elf64" is what you want. What makes you think so?

Best,
Frank

Assembling ther same files with /* */ comments on Fedora 31 both gcc-9.3 and clang-9.0 have no problems with the comments. Should not NASM try to be compatrible with the native assemblers in regard to comments as it tries to be compatible in regard to assembly langUage syntax. Has anyone ever brought this up before ? If not I am a bit surprised.

NASM *is* a native assembler. It follows Intel syntax. gas diverged from the original syntax.
gcc will not have problems with /*---*/ comments as gcc is a C compiler, and you are passing it standard C comments.
I don't know "clang", but from the name I assume that is also a C compiler, so same applies.

What is standard for one programming language does not have to be standard for others. Assembly language came before C, so by your reasoning, C standard must be wrong :)

I guess I am out of luck with nasm, as all the elf 64 assembly files in the Boost context library are gas syntax. Even without comments nasm did not like the syntax. The only thing I can do is to suggest to the Boost context library maintainer that he create elf 64 assembly files following the Intel syntax and not the gas syntax, although I personally, not being astute in assembly language, do not know the difference between the gas and Intel syntax.

You are correct that both gcc and clang are C/C++ compilers but they have an assembly language component that is able to assemble source files. Evidently their assembly language component not only understands C/C++ syle comments but also the gas syntax.

My reasoning never said anything about any language being more valid than any other language. Not knowing assembly very well and not knowing nasm I had just assumed that nasm could handle any syntax that native assemblers could. My assumption was wrong in relationship to the assembly files in the Boost context library, but I did not mean in any way to put down nasm.

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Assembling an elf64 file on Windows
« Reply #8 on: May 13, 2020, 07:20:35 PM »
I hear you. No idea why gnu opted to use a different syntax in their assembler. I've only ever used assemblers that use the Intel syntax, so I'm not up on the differences. Gnu is very widely used though, so if you are already learning how to use gas, it might be worth your time getting to know both. I'm pretty sure there is sample code online for both.
My graphics card database: www.gpuzoo.com

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Assembling an elf64 file on Windows
« Reply #9 on: May 13, 2020, 09:02:37 PM »
There are converters - "intel2gas", "a2i", "i2a". My experience is that they don't work very well. Yasm will accept both Intel and AT&T syntax. Might be something you'd want to look at?

Best,
Frank

« Last Edit: May 13, 2020, 09:07:43 PM by Frank Kotler »