[PATCH] D48756: Add option for section ordering

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 15:27:01 PDT 2018


pcc added a comment.

I think it's important to understand exactly how the Linux kernel is sensitive to being linked, so that once we understand the root cause, we can develop an appropriate fix. It may be that the root cause is a deliberate dependency on an implementation detail, but that doesn't necessarily mean that the right fix is to add a flag, it could mean that we can develop a more targeted fix that doesn't require a flag. Or it could just be a bug, in which case we can fix it uncontroversially without needing to add a flag. In general I think it's important to find a solution that avoids adding flags because that increases the maintenance burden of the program. Here's an excellent article I recently read that makes the point better than I can: http://neugierig.org/software/blog/2018/07/options.html

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`.


https://reviews.llvm.org/D48756





More information about the llvm-commits mailing list