Live data from Hacker News

The .a file is a relic: Why static archives were a bad idea all along

medium.com

21–30 of 136 posts

Re: The .a file is a relic: Why static archives were a bad idea all along

#21
post #20

Something I've never quite understood is why can't you statically link against an so file? What specific information was lost during the linking phase to create the shared object that presents that machine code from being placed into a PIE executable?

wcc can do that for you: https://github.com/endrazine/wcc

Re: The .a file is a relic: Why static archives were a bad idea all along

#22
post #20

Something I've never quite understood is why can't you statically link against an so file? What specific information was lost during the linking phase to create the shared object that presents that machine code from being placed into a PIE executable?

wcc can do that for you: https://github.com/endrazine/wcc

Woah this is really awesome! Thanks for sharing, this made my day.

Re: The .a file is a relic: Why static archives were a bad idea all along

#23
post #20

Something I've never quite understood is why can't you statically link against an so file? What specific information was lost during the linking phase to create the shared object that presents that machine code from being placed into a PIE executable?

You can, but why?

Re: The .a file is a relic: Why static archives were a bad idea all along

#24

It is unclear to me what the author's point is. Its seems to center on the example of DPDK being difficult to link (and it is a bear, I've done it recently). But its full of strawmen and falsehoods, the most notable being the claims about the deficienies of pkg-config. pkg-config works great, it is just very rarely produced correctly by CMake. I have tooling and a growing set of libraries that I'll probably open sour…

The only exception to this general rule (which, to be clear, I agree with) is when your code for whatever links to LGPL licensed code. A project I'm a major contributor of does this (we have no choice but to use these libraries, due to the requirements we have, though we do it via implib.so (well, okay, the plan is to do that)), and so dynamic linking/DLL hell is the only path we are able to take. If we link statically to the libraries, the LGPL pretty much becomes the GPL.

Re: The .a file is a relic: Why static archives were a bad idea all along

#25

It is unclear to me what the author's point is. Its seems to center on the example of DPDK being difficult to link (and it is a bear, I've done it recently). But its full of strawmen and falsehoods, the most notable being the claims about the deficienies of pkg-config. pkg-config works great, it is just very rarely produced correctly by CMake. I have tooling and a growing set of libraries that I'll probably open sour…

> Static libraries have lots of game-changing advantages, but performance, security, and portability are the biggest ones.

No idea how you come to that conclusion, as they are definitively no more secure than shared libraries. Rather the opposite is true, given that you (as end user) are usually able to replace a shared library with a newer version, in order to fix security issues. Better portability is also questionable, but I guess it depends on your definition of portable.

Re: The .a file is a relic: Why static archives were a bad idea all along

#26
post #23
post #20

Something I've never quite understood is why can't you statically link against an so file? What specific information was lost during the linking phase to create the shared object that presents that machine code from being placed into a PIE executable?

You can, but why?

At a fundamental level I don't understand why we have two separate file types for static and dynamic libraries. It seems primarily for historical reasons?

The author proposes introducing a new kind of file that solves some of the problems with .a filed - but we already have a perfectly good compiled library format for shared libraries! So why can't we make gcc sufficiently smart to allow linking against those statically and drop this distinction?

Re: The .a file is a relic: Why static archives were a bad idea all along

#28
post #19
post #2

I actually wrote a tool a to fix exactly this asymmetry between dynamic libraries (a single object file) and static libraries (actually a bag of loose objects) I never really advertised it, but what it does is take all the objects inside your static library, and tells the linker to make a static library that contains a single merged object. https://github.com/tux3/armerge The huge advantage is that with a single obje…

Is there any actual functional difference between the author’s proposed ET_STAT and an appropriately prepared ET_RET file? For that matter, I’ve occasionally wondered if there’s any real reason you can’t statically link an ET_DYN (.so) file other than lack of linker support.

I think everything that you would want to do with an ET_STAT file is possible today, but it is a little off the beaten path, and the toolchain command line options today aren't as simple as for dynamic libraries (e.g. figuring out how to hide symbols in a relocatable object is completely different on the GNU toolchain, LLVM on Linux, or Apple-LLVM which also supports relocatable objects, but has a whole different object file format).

I would also be very happy to have one less use of the legacy ar archive format. A little known fact is that this format is actually not standard at all, there's several variants floating around that are sometimes incompatible (Debian ar, BSD ar, GNU ar, ...)

Re: The .a file is a relic: Why static archives were a bad idea all along

#29
post #23
post #20

Something I've never quite understood is why can't you statically link against an so file? What specific information was lost during the linking phase to create the shared object that presents that machine code from being placed into a PIE executable?

You can, but why?

Because I want my program to run on other people's computers.

Re: The .a file is a relic: Why static archives were a bad idea all along

#30
post #23

Earlier quoted context omitted.

You can, but why?

Because I want my program to run on other people's computers.

I think the question isn’t why statically link but rather why bother with .a files and instead use the shared libraries all the time (even if only to build a statically linked executable).
Post reply on HN