Highload-fun / platform

33 stars 0 forks source link

C++ with Assembler Files #13

Open aig opened 3 years ago

aig commented 3 years ago

Hi!

I am trying to create a minimal working С++ with assembly language program.

On my server, the program is compiled and executed successfully, but when I try to create the same in the platform, an error occurs: Error: Exit with code 1: cannot run file: No such file or directory I created an empty main.cpp and created main.S main.S:

.intel_syntax prefix

#include <asm/errno.h>
#include <asm/mman.h>
#include <asm/unistd.h>

#define SYSCALL_NUMBER %eax

.bss
.align 4 << 20

.text
.globl _start
_start:

jmp exit

exit:
mov SYSCALL_NUMBER, __NR_exit_group
syscall
ud2

compile locally like this g++ -nostdlib main.S

sergei-svistunov commented 3 years ago

Hi. I can't check now, but as far I remember the command looks like g++ main.cpp <your arguments> . I'll return in a week and try to help if you not figure out.

aig commented 3 years ago

Thank you for your response!

Unfortunately, I could not get the program to work, but if I remove "-nostdlib", the problem disappears. To be honest, it is not clear why it needed to run the program on the platform.

sergei-svistunov commented 3 years ago

Hi!

I am trying to create a minimal working С++ with assembly language program.

On my server, the program is compiled and executed successfully, but when I try to create the same in the platform, an error occurs: Error: Exit with code 1: cannot run file: No such file or directory I created an empty main.cpp and created main.S main.S:

.intel_syntax prefix

#include <asm/errno.h>
#include <asm/mman.h>
#include <asm/unistd.h>

#define SYSCALL_NUMBER %eax

.bss
.align 4 << 20

.text
.globl _start
_start:

jmp exit

exit:
mov SYSCALL_NUMBER, __NR_exit_group
syscall
ud2

compile locally like this g++ -nostdlib main.S

The binary requires the /lib64/ld-linux-x86-64.so.2 library, but ldd doesn't show it:

$ ldd a.out 
    statically linked

Each binary runs in sandbox, that's why it doesn't have an access to whole file system and the file wasn't added to sandbox because ldd didn't show it. Removing --nostdlib flag has fixed it.

sergei-svistunov commented 3 years ago

Thank you for your response!

Unfortunately, I could not get the program to work, but if I remove "-nostdlib", the problem disappears. To be honest, it is not clear why it needed to run the program on the platform.

What do you mean?

aig commented 3 years ago

Thank you for your response! Unfortunately, I could not get the program to work, but if I remove "-nostdlib", the problem disappears. To be honest, it is not clear why it needed to run the program on the platform.

What do you mean?

I mean I only manage to run it with this command "g++ main.S" but not with this "g++ -nostdlib main.S"

kytans commented 4 months ago

Try -static -nostdlib instead of just -nostdlib, it seems to work.