[PATCH] D48756: [gold-plugin] Add option for section ordering

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 17:07:32 PDT 2018


void added a comment.

In https://reviews.llvm.org/D48756#1159410, @pcc wrote:

> In https://reviews.llvm.org/D48756#1159376, @void wrote:
>
> > In https://reviews.llvm.org/D48756#1159339, @pcc wrote:
> >
> > > I want to help you get this fixed, so I had one idea about what the root cause might be. Normally the linker will strip the name of the function from the output section when `-function-sections` is enabled, so `.text.foo` becomes `.text` in the output file. What that means is that without any special flags, `-function-sections` shouldn't normally change the output in any observable way. One case in which it is observable is when creating a relocatable object file with the `-r` flag. I happen to know that Linux kernel modules (`.ko` files) are represented as relocatable object files, so my suspicion is that the Linux kernel loader doesn't like section names of the form `.text.foo` in `.ko` files. If that's the case, a better fix would be to disable function sections only when creating a relocatable object file. That seems fine to me because relocatable files cannot usually be optimized by the linker. (What it probably also means is that in a later change we will want to save the `-ffunction-sections` and `-fdata-sections` flags passed at compile time and use them at link time. That would make things more complicated if we had just added a flag, because now we need to decide what to do if the link-time flag conflicts with the compile-time flag.) You can check whether `-r` was passed by checking whether the `LDPT_LINKER_OUTPUT` tag passed to the plugin is `LDPO_REL`.
> >
> >
> > The `-r` flag is being used, so your analysis is probably correct. From looking at the code, the kernel turns on function/data sections only when the `CONFIG_SPLIT_SECTIONS` option is set. The issue with disabling function sections for `.ko` files is that the gold linker doesn't know that they're turned off for those files. That information is lost because the command line information is lost.
>
>
> It's certainly lost at compile time right now. Putting no-function-sections behind `-r` isn't as good as using the compile-time flags, but it seems like it would make things more likely to work in cases where the consumer of the output file cares about section names, so it seems like it would do until the flag gets hooked up properly.
>
> > Also, I believe I was seeing these function sections in non-`.ko` files (after the final link).
>
> Can you double check which kind of files they were? It's possible that they were non-`.ko` relocatable files that might have been used to create the final image.


They're normal `.o` files. For example, `net/ipv6/ndisc.c` is compiled without those flags, but gets function sections during linking. (The linking uses the `-r` flag. Without it the link fails with a litany of unresolved references.)


https://reviews.llvm.org/D48756





More information about the llvm-commits mailing list