It was not GCC’s fault

Okay so… remember that I said that there was a GCC issue blocking my work toward the new Gentoo/FreeBSD 6.0 stage? Well it wasn’t GCC’s fault.
For some reasons GCC defaults to static libgcc when –as-needed is not supported by the platform, and for some reasons –as-needed is not supported on FreeBSD (I have actually no clue why).

The problem points again at binutils. We really need to patch it to respect Okay, this time I’m going down to fixing that in a proper way. I’ve cut down the original 599KiB patch into a 272KiB patch, and that seems ot apply over 2.16.1 almost flawlessy, and seems also to not cause it segfault as it was before.

It seems to me that there are at least two patches mixed in that stuff, one is an ld patch that does what we need, the other is a big bfd patch that updates FreeBSD support.
I’ll see to check this deeply so that I can submit the changes upstream, so that binutils would work on FreeBSD out of the box.

Now I’m trying to understand how binutils works, not a simple task but it should be feasible..

I wish to thank vapier and Kevin who pointed me to the right direction, and solar and az who helped me debugging the problem the first time 🙂

Update 13:45 GMT+1
Okay the issue is bigger than I thought before. I still see the crashes with LD. This time, tho, I’m going to track them down and resolve them. To do that I’m using keepwork FEATURES (as the code is in generated files) and -ggdb flag, without -O or inlining makes difficult finding the stuff.
I need to understand how the internals of ld works, not an easy task at all. But I hope I’m able to get something useful out of it, if nothing else, at least some experience.

For who is wondering, this is finally how the libraries’ search seems to work:
a) for libraries passed to commandline linking (-l) they are looked up in the default library paths (/lib /usr/lib /usr/local/lib) and in binutils’ library directory, then in paths provided at commandline (-L);
b) for libraries that are in DT_NEEDED fields, the search happens in runpaths, and if it’s a native linker in the cache.

And now (again while eating) I was able to find what the problem was (a variable was passed as string while the new version requires a struct)… I’ll clean up the patch and prepare it to be sent upstream…

Update 16:27 GMT+1
Okay, I had the patch for ld hints working, both for 2.16.1 and I sent them to the upstream mailing list and opened a bug for them. Now I’m rebuilding world in the vm to see if it works or not.
That is not going to be the only thing I have to fix, but at least it’s another step forward to reach Gentoo/FreeBSD 6.0 stage.