Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling NASM from a C program using system() produces different object code then calling using Bash
    primarykey
    data
    text
    <p>I've implemented a reasonably good optimizing compiler (for a toy language), and have come across a rather puzzling scenario. I can take an input file and produce assembly from it, so in that respect the "compiler" is finished. If I take that assembly file assemble it with NASM and link it to my runtime support library with G++ (the runtime needs libstdc++), I get a working executable, with no errors. However, I'd like to be able to compile to an executable in one command, so I added some calls to <code>system</code> to my compiler, passing the EXACT SAME COMMANDS as I was using in bash. When I run the compiler, it seems to assembly properly, but the linking step (again, using g++) fails with an <code>undefined reference to main</code>. Confused, I attempted to link manually (without reassembling, so I was using the object file produced by the NASM run with <code>system</code>, and received the same error. If I reassemble using the new compiler's assembly output, I have no problems, which has led be to believe that NASM is the problem. Like I said, the commands are exactly the same (I literally copied and pasted them just to make sure after the first time). Is this environment variables or something? What's going on?</p> <p>EDIT: I manually assembled an object file, again using the same command as the one in the compiler, and I did a vim diff between the two. The compiler-generated one seems to only contain the ELF header.</p> <p>EDIT 2: A screenshot of the diff<img src="https://i.stack.imgur.com/qnshr.png" alt="screenshot"></p> <p>EDIT 3: I tried using <code>system</code> to call a Perl script that in turn would call NASM and G++, still no luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload