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

Error when compiling with --link-libc=no #1937

Open
amarz45 opened this issue Feb 7, 2025 · 4 comments
Open

Error when compiling with --link-libc=no #1937

amarz45 opened this issue Feb 7, 2025 · 4 comments
Assignees
Labels
Additional info please Further information is requested

Comments

@amarz45
Copy link

amarz45 commented Feb 7, 2025

Let’s say I have the following C3 program:

import std::io;

fn void main() {
    io::printn("hello");
}

If I try to compile with c3c compile main.c3, it works as expected. However, I want to compile a statically-linked executable. But if I try to compile with c3c compile --link-libc=no main.c3, I get the following error:

ld.lld: error: unable to find library -ldl
Failed to create an executable: (null)
@lerno lerno added the Bug Something isn't working label Feb 8, 2025
@lerno lerno self-assigned this Feb 8, 2025
@lerno lerno added Discussion needed This feature needs discussion to iron out details and removed Bug Something isn't working labels Feb 8, 2025
@lerno
Copy link
Collaborator

lerno commented Feb 8, 2025

I can't reproduce this. What version of C3 are you using? I think it was fixed in 0.6.6.

@lerno lerno added Additional info please Further information is requested and removed Discussion needed This feature needs discussion to iron out details labels Feb 8, 2025
@amarz45
Copy link
Author

amarz45 commented Feb 8, 2025

I realized that the version of C3 I was using was 0.6.5. I updated to the latest commit from the master branch. However, now when I try to compile with --link-libc=no, I get a different error:

ld.lld: error: undefined symbol: __stack_chk_fail
>>> referenced by builtin.c3:0
>>>               std.core.builtin.o:(std.core.builtin.panicf)
>>> referenced by formatter_private.c3:0
>>>               std.io.o:(std.io.Formatter.floatformat)
>>> referenced by formatter_private.c3:0
>>>               std.io.o:(std.io.Formatter.ntoa)
>>> referenced 2 more times
Failed to create an executable: (null)

@lerno
Copy link
Collaborator

lerno commented Feb 9, 2025

It's the stack protector added by default. Easiest way to get rid of it is to use -g0

@amarz45
Copy link
Author

amarz45 commented Feb 9, 2025

When compiling with --link-libc=no -g0, I get this linker warning:

ld.lld: warning: cannot find entry symbol _start; not setting start address

And then when trying to run the program, I get:

segmentation violation--core dumped

It seems like -g0, when combined with --link-libc=no, causes the entry point to the program to be missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Additional info please Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants