[Bug 232291] ld.bfd (newer) and ld.lld (6 and imho 7) create empty sections when they should not

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Oct 15 15:44:43 UTC 2018


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=232291

            Bug ID: 232291
           Summary: ld.bfd (newer) and ld.lld (6 and imho 7) create empty
                    sections when they should not
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: bz at FreeBSD.org
                CC: arichardson at FreeBSD.org, dim at FreeBSD.org,
                    emaste at freebsd.org

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:

39 SECTIONS
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.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list