Bug#1143807: hppa-linux-gnu-gcc does not honor -ffreestanding, generating referencs to memset

Michael Tokarev <[email protected]>
Newsgroups gmane.linux.debian.devel.gcc
Message-ID <e4407d16-0d9b-4f41-b96e-dc7db05377f2__784.151342098482$1786097246$gmane$org@tls.msk.ru>
On 8/7/26 12:42, Michael Tokarev wrote:
> Source: gcc-16
> Version: 16.1.0-3
> Severity: normal
> X-Debbugs-Cc: [email protected]
> User: [email protected]
> Usertags: hppa
> 
> Building firmware with hppa and hppa64 gcc, with option
> -ffreestanding.  Starting with gcc-16, the following code
> 
>      struct tpm_log_entry le = {
>          .hdr.pcrindex = pcpes->pcrindex,
>          .hdr.eventtype = pcpes->eventtype,
>      };
> 
> causes the following error to me emitted at link time:
> 
>   hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o: in function `hash_log_extend':
>   ccode32flat.o.tmp.c:(.text+0x5400): undefined reference to `memset'
>   hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o(.text+0x5400): cannot reach memset
>   ccode32flat.o.tmp.c:(.text+0x5400): relocation truncated to fit: R_PARISC_PCREL22F against undefined symbol `memset'
> 
> The struct in question is a bit large, so it really needs
> some memory zeroing in this case.  But the compiler is given
> -ffreestanding.

Actually it is more interesting.  The firmware does have
memset() definition in there.

The original command line:

  hppa64-linux-gnu-ld -N -T o64/pafirmware.lds o64/head.o o64/version.o -X -o o64/hppa-firmware64.img -e startup \
     --as-needed o64/ccode32flat.o /usr/lib/gcc/hppa64-linux-gnu/16/libgcc.a

produces the original error messages:

  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o: in function `hash_log_extend':
  ccode32flat.o.tmp.c:(.text+0x5400): undefined reference to `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o(.text+0x5400): cannot reach memset
  ccode32flat.o.tmp.c:(.text+0x5400): relocation truncated to fit: R_PARISC_PCREL22F against undefined symbol `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o: in function `tpm_add_measurement_to_log':
  ccode32flat.o.tmp.c:(.text+0x7130): undefined reference to `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o(.text+0x7130): cannot reach memset
  ccode32flat.o.tmp.c:(.text+0x7130): relocation truncated to fit: R_PARISC_PCREL22F against undefined symbol `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o: in function `tpm20_write_EfiSpecIdEventStruct':
  ccode32flat.o.tmp.c:(.text+0x72d8): undefined reference to `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o(.text+0x72d8): cannot reach memset
  ccode32flat.o.tmp.c:(.text+0x72d8): relocation truncated to fit: R_PARISC_PCREL22F against undefined symbol `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: ccode32flat.o.tmp.c:(.text+0x73a0): undefined reference to `memset'
  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/ccode32flat.o(.text+0x73a0): cannot reach memset
  ccode32flat.o.tmp.c:(.text+0x73a0): relocation truncated to fit: R_PARISC_PCREL22F against undefined symbol `memset'

all these are about local variable assignments like the
above.  But adding memset() symbol to the command line
fails differently:

  hppa64-linux-gnu-ld -N -T o64/pafirmware.lds o64/head.o o64/version.o -X -o o64/hppa-firmware64.img -e startup \
     --as-needed o64/ccode32flat.o o64/src/string.o /usr/lib/gcc/hppa64-linux-gnu/16/libgcc.a

(note the added o64/src/string.o here).  Now it complains about multiple
definitions of memset!

  /usr/bin/hppa64-linux-gnu-ld.bfd: o64/src/string.o: in function `memcpy':
  /build/pkg/build/b/hppa-fw/src/string.c:171: multiple definition of `memcpy'; \
   o64/ccode32flat.o:/build/pkg/build/b/hppa-fw/./src/string.c:171: first defined here

So the symbol is actually there, but somehow the linker can't find
it if the reference is made by gcc itself.

hmm..

/mjt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.