Open iffy opened 9 months ago
Right, this reminds me of the following: https://stackoverflow.com/questions/53414293/gcc-differently-treats-an-object-and-a-static-library-regarding-undefined-symbol - ie there's a difference of linking objects vs static libraries - maybe there's a way to get the static-library-like linking even when using object files? something to investigate..
How about this latest change? This lets library users keep the existing behavior:
nim c myprog.nim
Or compile with their own libbearssl.a
nim c -d:bearStaticLibPath=/path/to/libbearssl.a myprog.nim
How about this latest change? This lets library users keep the existing behavior:
the thing missing here above all is the step that ensures that the static library corresponds to the actual source code of bearssl and is compiled using the same options, compiler and flags as the nim code (optimization flags, LTO etc) - this is the difficulty when working with .a
files without the powers that make
has, namely to keep track of dependencies - nim does a poo job of this even with .compile
and with the static linking option, we go even further away from "just works" because of the manual steps involved.
the way one would typically get the same end result with a modern toolchain is to do LTO + whole-program optimisation or possibly function/data sections (-ffunction-sections
and friends) + link-time garbage collection, which neatly works around nim's deficiences but puts some additional constraints on the end user
Thanks for taking a look! I'll admit that I don't have recent expertise with compiling, so if you think it's not a good idea, that's fine. I'm not clear if you're worried about things being broken because of this change, or if you're just worried they won't be optimal.
we go even further away from "just works" because of the manual steps involved.
This PR makes linking to a .a
opt-in. So this library still "just works" as-is. If someone wants to link to a .a
, they'll be responsible for figuring out how to do that and must explicitly decide to do so (with -d:bearStaticLibPath=/path/to/libbearssl.a
). This PR makes it possible, but doesn't cause it to happen by default.
the way one would typically get the same end result with a modern toolchain...
By "same end result" here, do you mean the trimming unused bearssl symbols magic that BearSSL does?
Again, thanks for taking the time (and for publishing this library).
This addresses #53
I found the key in
bearssl/csources/README.txt
:So with the code in this PR, I do the following on macOS:
And get this output:
It works! (At least for MD5).
But I don't know the correct way to change this library to either build the static lib or get users to build the static lib themselves. Thoughts?