[PATCH] D24782: Do not merge input sections if --relocatable.

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 03:40:24 PDT 2016


peter.smith added a comment.

I've done a bit of digging on the uses for ld -r relocatable. It seems to be that the primary and perhaps only use case for the existing behaviour of ld -r are relocatable kernel modules (on linux files with the .ko extension). Single file modules can be loaded directly by a simple linker/loader in the kernel, more complex ones are combined with ld -r (https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt).

My limited understanding of kernel modules is that they are written in C with no use of the standard library allowed. There is no support for C++ and certainly not C++ exceptions.

While I couldn't say for sure I would expect that a kernel module will rely on being "pre-processed" by ld -r first, if only to collate together the module id and some other custom sections.

As to what this tells us; I think the ability to combine sections has a reasonable use case. I don't think that trying to make all possible features work seamlessly with it is strictly necessary. Some possible options:

- Do not support kernel modules, this would be a problem for freebsd if their kernel modules work this way. I'm sure linux kernel modules can/will use GNU ld.
- ld -r works as it is but does not guarantee to support complicated cases like ARM C++ exceptions (error message given?)
- ld -r works as it is when provided with a linker script, but by default it won't combine sections.
- Make ld -r work, at least for those who are using its output as an input to another system linker.

I suspect that if freebsd's module system uses relocatable objects like Linux I think the existing behaviour of ld -r will be important enough to preserve in some form. Given that kernel modules don't support C++ I think it is acceptable, if not ideal, to not support ARM C++ exceptions with ld -r combining sections.

Some comments on the patch:

- Last time I tried ld -r wasn't working at all with linker scripts but it will be worth checking that the ldscript interacts as expected. At present it looks like the individual InputSections are not combined, but they are renamed to whatever OutputSection they matched in the linker script.
- The SHF_LINK_ORDER will still need a bit of added complexity, the sh_link to the InputSection will need to be updated to whatever the section index of the OutputSection is.


https://reviews.llvm.org/D24782





More information about the llvm-commits mailing list