Bug 232291 - ld.bfd (newer) and ld.lld (6 and imho 7) create empty sections when they should not
Summary: ld.bfd (newer) and ld.lld (6 and imho 7) create empty sections when they shou...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain mailing list
Depends on:
Blocks: 230857
  Show dependency treegraph
Reported: 2018-10-15 15:44 UTC by Bjoern A. Zeeb
Modified: 2019-06-08 17:46 UTC (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Bjoern A. Zeeb freebsd_committer 2018-10-15 15:44:40 UTC
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:

40		{
41		        set_pcpu        :
42		        {
43		                *(set_pcpu)
44		                . = . + ABSOLUTE (___set_pcpu_pad) ;
45		        }
46		}

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.