News for hackers. Stuff that matters.
Re:Zig cc: A drop-in replacement for GCC/Clang by dman on Tuesday March 24, 2020 @08:24PM (#22680614)
You cant statically compile in glibc right?
Re:Zig cc: A drop-in replacement for GCC/Clang by spatulon on Tuesday March 24, 2020 @08:28PM (#22680646)
sure you can:

    $ cat hello.c
    #include <stdio.h>

    int main() {
        printf("hello world!\n");
    }
    $ gcc -o hello hello.c
    $ ldd hello
            linux-vdso.so.1 (0x00007ffff9da0000)
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fed449d0000)
            /lib64/ld-linux-x86-64.so.2 (0x00007fed45000000)
    $ gcc -o hello hello.c -static
    $ ldd hello
            not a dynamic executable
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @09:50PM (#22681250)
You can, but it is not supported. Certain features (NSS, iconv) will not work.
Re:Zig cc: A drop-in replacement for GCC/Clang by otabdeveloper2 on Wednesday March 25, 2020 @03:08AM (#22682570)
> Certain features (NSS, iconv) will not work.

If you're the kind of person who wants static linking then you really don't want these features.

The real problem is that statically linked programs under Linux don't (didn't?) support VDSO, which means that syscalls like gettimeofday() are suddenly orders of magnitude slower.

In the end, we had to do a kind of pseudo-static linking - link everything static except glibc.

Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Wednesday March 25, 2020 @03:38AM (#22682680)
I think the vDSO page is mapped into every process regardless of how the program is linked, although you may have difficulty using it.
Re:Zig cc: A drop-in replacement for GCC/Clang by justincormack on Wednesday March 25, 2020 @03:44AM (#22682704)
Vdso is supported with static linking in Musl libc at least.
Re:Zig cc: A drop-in replacement for GCC/Clang by luizfelberti on Tuesday March 24, 2020 @08:57PM (#22680858)
I don't think the parent comment's point was if this was technically possible.

glibc is GPL licensed, and the GPL explicitly forbids statically linking to it unless your code is GPL too.

Thus any non-GPL project has it's license tainted by the GPL if you statically link it.

It's not a technical limitation, it's a legal one.

Re:Zig cc: A drop-in replacement for GCC/Clang by cesarb on Tuesday March 24, 2020 @09:17PM (#22681010)
This is false. The license for glibc is the LGPL, not the GPL, and the LGPL has an exception to allow static linking without the whole code having to be under the LGPL, as long as the .o files are also distributed to allow linking with a modified glibc ("As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice [...] and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library.")
Re:Zig cc: A drop-in replacement for GCC/Clang by luizfelberti on Wednesday March 25, 2020 @12:01AM (#22681837)
Sounds like I got conned by my (poor) memory. I should have re-googled this before posting, thanks for the correction.
Re:Zig cc: A drop-in replacement for GCC/Clang by jfkebwjsbx on Wednesday March 25, 2020 @04:06AM (#22682795)
Yes, but for many projects it means no static linking in practice.
Re:Zig cc: A drop-in replacement for GCC/Clang by yarrel on Tuesday March 24, 2020 @09:47PM (#22681233)
This isn't a legal limitation.

It's FUD.

See here -

https://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynami...

Re:Zig cc: A drop-in replacement for GCC/Clang by luizfelberti on Wednesday March 25, 2020 @12:04AM (#22681846)
Thanks for the link, that's very useful. I should have re-googled this stuff instead of commenting "from memory", sorry for spreading the FUD :/
Re:Zig cc: A drop-in replacement for GCC/Clang by a1369209993 on Wednesday March 25, 2020 @11:47AM (#22685672)
Also, right above that: https://www.gnu.org/licenses/gpl-faq.html#GPLStaticVsDynamic

Dynamically linking a GPL library is the same as statically linking a GPL library; the resulting executable must be GPL-licensed.

Re:Zig cc: A drop-in replacement for GCC/Clang by sandov on Tuesday March 24, 2020 @11:10PM (#22681644)
That's also a good reason to avoid glibc and switch to a musl-based system.
Re:Zig cc: A drop-in replacement for GCC/Clang by freemint on Tuesday March 24, 2020 @09:20PM (#22681039)
I might be uneducated but wasn't there a "system library exception" or something like that in GPL to prevent these problems?