/usr/bin/ld: /tmp/ccrqA7G3.o: relocation R_X86_64_32 against
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
@JameezPlays I haven't been able to figure out why yet, but it seems that the linker is defaulting to 32bit mode. Assembling the code into an object file and then linking seems to work though.
The program as a whole still doesn't work though, so getting it to link seems like a bit of a pointless achievement, since it will still segfault on execution.
It looks like he wrote this program in C and then compiled it to assembly, so I cleaned up the syntax into a more readable GNU assembler syntax that will actually print "hello world".
#!/usr/bin/bash
#
# Assemble the program.
as -o hello.o hello.s
# Link the program using the 64-bit dynamic interpreter.
ld hello.o -o hello -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc --format elf64-x86-64
# Execute the resulting binary.
./hello
Unfortunately, while this code will print the message, it too segfaults at the end, and I'm not sure why yet.
Still, this example is great for demonstrating how to use the popen function to be able to write assembly language in Repls, and the best part is that Repl.it seems to include NASM by default, so we can "solve" the problem by just cutting the Gordian knot and not bothering with GNU assembler syntax lol.
@JameezPlays You could, yea. I got caught up more in the details of just trying to get it to work, but you're absolutely right; you could just set it up to just run through the repl configuration file.
Assembly compiler
uses a simple little trick to allow you to compile and run raw assembly on repl.it
/usr/bin/ld: /tmp/ccrqA7G3.o: relocation R_X86_64_32 against
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
/bin/sh: 1: ./run: not found
The program as a whole still doesn't work though, so getting it to link seems like a bit of a pointless achievement, since it will still segfault on execution.
It looks like he wrote this program in C and then compiled it to assembly, so I cleaned up the syntax into a more readable GNU assembler syntax that will actually print "hello world".
I'm assembling and linking it like this:
Unfortunately, while this code will print the message, it too segfaults at the end, and I'm not sure why yet.
Still, this example is great for demonstrating how to use the
popen
function to be able to write assembly language in Repls, and the best part is that Repl.it seems to include NASM by default, so we can "solve" the problem by just cutting the Gordian knot and not bothering with GNU assembler syntax lol.