Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Attempt to add basic libraries for Assembly #4230

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

partouf
Copy link
Contributor

@partouf partouf commented Nov 2, 2022

Would fix #4160

Doesn't actually work. Linking with just ld to libc results in a bad executable that won't execute. (bash: ./ce-asm-executable: No such file or directory)

It might be that you can't actually use libc out of context of all the crt code and gcc.

Examples on the internet seem to just use gcc to link, for example

But as soon as you link with gcc, you cannot provide a _start, you have to provide a main and a host of different functions.

http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html gives a nice overview, especially with the graph at the end.

Perhaps this is the point where instead we start providing different libc implementations, because gnu's one is just too much spaghetti...

@partouf partouf changed the base branch from main to asmtotypescript November 2, 2022 04:15
Base automatically changed from asmtotypescript to main November 2, 2022 08:58
@partouf partouf changed the title [DRAFT] Attempt to add basic libraries for C [DRAFT] Attempt to add basic libraries for Assembly Nov 2, 2022
@partouf
Copy link
Contributor Author

partouf commented Dec 22, 2022

discord user sbdswr mentioned the following to work:

$ cat hello.s
extern puts

msg db "Hello, ld!", 0

global main
main:
    mov edi, msg
    call puts

    xor eax, eax
    ret
$ nasm -felf64 hello.s
$ ld -I/usr/lib64/ld-linux-x86-64.so.2 /usr/lib64/crt1.o -lc hello.o -o hello
$ ./hello
Hello, ld!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LIB REQUEST] libc for assembly
1 participant