Working on a possible solution for PR230857 it seemed that ld.bfd and ld.lld are bug compatible.
The old version of ld.bfd currently in HEAD (GNU ld 2.17.50 [FreeBSD] 2007-07-03
, from before the branch of stable/12) seems to do the expected thing on certain statements with regards to "Dot".
Newer versions of both ld.bfd (2.26) and ld.lld seem to fail to do the right thing.
Strangely enough in old times that behaviour was not documented and worked, for newer version is documented and fails.
One of the possible solution for the above mentioned PR as initially outlined in https://reviews.freebsd.org/D17512 was along the lines of the following linker script snippet:
41 set_pcpu :
44 . = . + ABSOLUTE (___set_pcpu_pad) ;
If ___set_pcpu_pad would be 0 the statement would be . = . + (sym==0) in which case, was the section non-existent/empty before should not be created. However it is with lld and the above mentioned bfd version at least.
According to https://sourceware.org/binutils/docs-2.31/ld/Output-Section-Discarding.html#Output-Section-Discarding it should not be created:
QUOTE >>> Other link script directives that allocate space in an output section will also create the output section. So too will assignments to dot even if the assignment does not create space, except for ‘. = 0’, ‘. = . + 0’, ‘. = sym’, ‘. = . + sym’ and ‘. = ALIGN (. != 0, expr, 1)’ when ‘sym’ is an absolute symbol of value 0 defined in the script. This allows you to force output of an empty section with ‘. = .’. <<<
We should make sure that the upstream linkers we use get fixed to properly work as documented and as at least one seems to have in the past. Having bug-compatiility between the two is not helpful at all.
While they are broken we might have to end up splattering sections over all kernel modules, adding BYTE(1)-kind padding to these sections and checking this and filtering this out in the in-kernel linker, which is extra noise, extra size, extra complexity, .. otherwise not needed, as well as possible problems with out-of-tree compiled kernel modules.