Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Jul 2019 13:51:09 -0700
From:      Mark Millard <marklmi@yahoo.com>
To:        FreeBSD Toolchain <freebsd-toolchain@freebsd.org>
Subject:   system-clang devel/powerpc64-binutils used to amd64->powerpc (32-bit) cross-build vs. the ld's secture-plt criteria: leads to build failure
Message-ID:  <DC6D8067-9EF5-49E6-8718-0412E0CBEC18@yahoo.com>

next in thread | raw e-mail | index | archive | help
Sometime at or before head -r349444 my historical src.conf variant
that i use to amd64->powerpc cross-build using devel/powerpc64-binutils
stopped working, getting:

--- libc.so.7.full ---
building shared library libc.so.7
/usr/local/powerpc64-unknown-freebsd13.0/bin/ld: bss-plt forced due to =
/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.pow=
erpc/tmp/usr/lib/crtbeginS.o
cc: error: linker command failed with exit code 1 (use -v to see =
invocation)
*** [libc.so.7.full] Error code 1


(I had not updated the head revision for a long time before
jumping to -349444 . I'll note that the issue does not seem
to be uniquely tied to crtbeginS.o but the
devel/powerpc64-binutils based builds stop teh build before
hitting other examples.)


The code for devel/powerpc64-bintuils has the comment:

	  /* Look through the reloc flags left by ppc_elf_check_relocs.
	     Use the old style bss plt if a file makes plt calls
	     without using the new relocs, and if ld isn't given
	     --secure-plt and we never see REL16 relocs.  */

(I'll show code around that later.)


For something like crtbeginS.o system-clang (from head) ends up with
the likes of the following with no use of any R_PPC_REL16* variants:

Relocation section with addend (.rela.text):
r_offset r_info   r_type              st_value st_name + r_addend
0000001c 00000d17 R_PPC_LOCAL24PC     00000000 _GLOBAL_OFFSET_TABLE_ + =
fffffffc
00000026 0000060e R_PPC_GOT16         00000008 =
__do_global_dtors_aux.completed + 0
00000036 00000f0e R_PPC_GOT16         00000000 __cxa_finalize + 0
00000042 0000100e R_PPC_GOT16         00000000 __dso_handle + 0
00000048 00000f12 R_PPC_PLTREL24      00000000 __cxa_finalize + 8000
0000004e 0000070e R_PPC_GOT16         00000004 __do_global_dtors_aux.p + =
0
00000062 0000070e R_PPC_GOT16         00000004 __do_global_dtors_aux.p + =
0
00000086 0000060e R_PPC_GOT16         00000008 =
__do_global_dtors_aux.completed + 0
000000ec 00000d17 R_PPC_LOCAL24PC     00000000 _GLOBAL_OFFSET_TABLE_ + =
fffffffc
000000f6 0000040e R_PPC_GOT16         00000000 __JCR_LIST__ + 0
00000106 00000e0e R_PPC_GOT16         00000000 _Jv_RegisterClasses + 0
00000112 0000040e R_PPC_GOT16         00000000 __JCR_LIST__ + 0

Relocation section with addend (.rela.fini):
r_offset r_info   r_type              st_value st_name + r_addend
00000000 00000b0a R_PPC_REL24         00000000 .text + 0

Relocation section with addend (.rela.init):
r_offset r_info   r_type              st_value st_name + r_addend
00000000 00000b0a R_PPC_REL24         00000000 .text + d4

Relocation section with addend (.rela.data):
r_offset r_info   r_type              st_value st_name + r_addend
00000000 00001001 R_PPC_ADDR32        00000000 __dso_handle + 0
00000004 00000c01 R_PPC_ADDR32        00000000 .dtors + 4

It appears that any .o ending up like crtbeginS.o leads to an overall
use of bss-plt instead of secure-lt use (absent an explicit
--secure-plt ). This ends up being tied to ->has_rel16 use.

The code that sets ->has_rel16 =3D 1 is:

	case R_PPC_REL16:
	case R_PPC_REL16_LO:
	case R_PPC_REL16_HI:
	case R_PPC_REL16_HA:
	  ppc_elf_tdata (abfd)->has_rel16 =3D 1;
	  break;

The plt_type =3D PLT_NEW use when ->plt_type is initially PLT_UNSET
requires ->has_rel16!=3D0 :

. . .
 if (htab->plt_type =3D=3D PLT_UNSET)
   {
     struct elf_link_hash_entry *h;
     if (htab->params->plt_style =3D=3D PLT_OLD)
	htab->plt_type =3D PLT_OLD;
     else if (info->shared
	       && htab->elf.dynamic_sections_created
	       && (h =3D elf_link_hash_lookup (&htab->elf, "_mcount",
					     FALSE, FALSE, TRUE)) !=3D =
NULL
	       && (h->type =3D=3D STT_FUNC
		   || h->needs_plt)
	       && h->ref_regular
	       && !(SYMBOL_CALLS_LOCAL (info, h)
		    || (ELF_ST_VISIBILITY (h->other) !=3D STV_DEFAULT
			&& h->root.type =3D=3D =
bfd_link_hash_undefweak)))
	. . .
     else
	{
	  bfd *ibfd;
	  enum ppc_elf_plt_type plt_type =3D htab->params->plt_style;
	  /* Look through the reloc flags left by ppc_elf_check_relocs.
	     Use the old style bss plt if a file makes plt calls
	     without using the new relocs, and if ld isn't given
	     --secure-plt and we never see REL16 relocs.  */
	  if (plt_type =3D=3D PLT_UNSET)
	    plt_type =3D PLT_OLD;
	  for (ibfd =3D info->input_bfds; ibfd; ibfd =3D =
ibfd->link.next)
	    if (is_ppc_elf (ibfd))
	      {
		if (ppc_elf_tdata (ibfd)->has_rel16)
		  plt_type =3D PLT_NEW;
		else if (ppc_elf_tdata (ibfd)->makes_plt_call)
		  {
		    plt_type =3D PLT_OLD;
		    htab->old_bfd =3D ibfd;
		    break;
		  }
	      }
	  htab->plt_type =3D plt_type;
	}
   }
 if (htab->plt_type =3D=3D PLT_OLD && htab->params->plt_style =3D=3D =
PLT_NEW)
   {
     if (htab->old_bfd !=3D NULL)
	info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"),
				htab->old_bfd);
     else
	info->callbacks->einfo (_("%P: bss-plt forced by profiling\n"));
   }
. . .


( ppc_elf_select_plt_layout in .../binutils-2_25_1/bfd/elf32-ppc.c )

For reference: the .meta file for the crtbeginS.o shows
(I split lines for readability):

# Meta data file =
/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.pow=
erpc/gnu/lib/csu/crtbeginS.o.meta
CMD cc \
-target powerpc-unknown-freebsd13.0 \
=
--sysroot=3D/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src=
/powerpc.powerpc/tmp \
-B/usr/local/powerpc64-unknown-freebsd13.0/bin/ \
-O2 -pipe  \
-B/usr/local/powerpc64-unknown-freebsd13.0/bin/ \
-DIN_GCC -DHAVE_LD_EH_FRAME_HDR -DDT_CONFIG -D__GLIBC__=3D3 \
-fno-inline-functions -fno-exceptions  -fno-zero-initialized-in-bss \
-fno-asynchronous-unwind-tables  -fno-omit-frame-pointer \
-I/usr/src/contrib/gcclibs/include -I/usr/src/contrib/gcc/config \
-I/usr/src/contrib/gcc -I.  -I/usr/src/gnu/usr.bin/cc/cc_tools  \
-g -std=3Dgnu89    -Qunused-arguments    \
-g0 -DCRT_BEGIN -DCRTSTUFFS_O -DSHARED -fpic  \
-c -o crtbeginS.o /usr/src/contrib/gcc/crtstuff.c
CWD =
/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.pow=
erpc/gnu/lib/csu

So noting is explicitly indicating to use secure-plt.

Doing some exploration with partial coverage of buildkernel via the
old system binutils (that does not abort for the bss-plt issue)
instead of devel/powerpc64-binutils reports more examples . . .

# grep bss-plt =
~/sys_typescripts/typescript_make_powerpcvtsc_nodebug_clang_bootstrap-amd6=
4-host-2019-06-27:01:44:37 | sort -u | more
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/crt1.o
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/crtbeginS.o
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(fixdfdi.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(fixsfdi.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(floatdidf.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(floatdisf.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(floatundidf.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(floatundisf.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(moddi3.o)
Using bss-plt due to =
/usr/obj/powerpcvtsc_clang/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr=
/lib/libgcc.a(umoddi3.o)
Using bss-plt due to accf_http.kld
Using bss-plt due to acl_nfs4.kld
Using bss-plt due to acl_posix1e.kld
Using bss-plt due to if_ae.kld
Using bss-plt due to if_age.kld
Using bss-plt due to reloc.o

The coverage of buildkernel is incomplete because of:

--- agp.ko.full ---
ld: agp.kld(.text+0x37a4): R_PPC_PLTREL24 reloc against local symbol
agp.kld: could not read symbols: Bad value
*** [agp.ko.full] Error code 1


=3D=3D=3D
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DC6D8067-9EF5-49E6-8718-0412E0CBEC18>