[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] m4/pma.m4: disable PIE in both CFLAGS and LDFLAGS consistent
From: |
arnold |
Subject: |
Re: [PATCH] m4/pma.m4: disable PIE in both CFLAGS and LDFLAGS consistently |
Date: |
Thu, 12 Jan 2023 00:50:58 -0700 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
I understand, but applying the patch is good insurance; who knows
how long it takes to fix toolchains...
Thanks,
Arnold
Sergei Trofimovich <slyich@gmail.com> wrote:
> On Wed, 11 Jan 2023 00:29:17 -0700
> arnold@skeeve.com wrote:
>
> > Hi.
> >
> > Thank you for the report. I will get this into the repo in the next
> > few days.
> >
> > Arnold
> >
> > Sergei Trofimovich <slyich@gmail.com> wrote:
> >
> > > In https://github.com/NixOS/nixpkgs/pull/207478#issuecomment-1378021841
> > > Alyssa noticed that gawk build fails on x86_64-unknown-linux-musl target
> > > in nixpkgs as:
> > >
> > > ld: .../x86_64-unknown-linux-musl/11.3.0/crtbegin.o:
> > > relocation R_X86_64_32 against hidden symbol `__TMC_END__'
> > > can not be used when making a PIE object
> > > ld: failed to set dynamic section sizes: bad value
>
> My apologies, underlying error happened due to downstream error of passing
> -no-pie to gcc and passing -pie to ld. Hence the failure to handle
> non-relocatable objects from crtbegin.o into a PIE binary (it should not
> have been PIE in the first place)!
>
> ld should always succeed linking -no-pie executables out of -fPIE (or -fPIC)
> .o files. Thus it's a downstream failure. It if does not it's a toolchain bug.
>
> I think this patch is still a correct thing to do, but it's not fundamental
> to fix the failure. Just a minor optimization.
>
> > > This happens because both compiler (CFLAGS=-fPIE) and linker
> > > (LDFLAGS=-pie) enable PIE by default.
> > >
> > > As a result just disabling linker flag is not enough and `ld`
> > > detects unresolvable dynamic relocations for non-PIE binary.
> > >
> > > The change disables PIE for both CFLAGS and LDFLAGS.
> > > ---
> > > m4/pma.m4 | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/m4/pma.m4 b/m4/pma.m4
> > > index c0535a26..73f6b316 100644
> > > --- a/m4/pma.m4
> > > +++ b/m4/pma.m4
> > > @@ -19,9 +19,13 @@ then
> > > use_persistent_malloc=yes
> > > case $host_os in
> > > linux-*)
> > > + # Guard against toolchains that default to CFLAGS=-fPIE
> > > LDFLAGS=-pie
> > > AX_CHECK_COMPILE_FLAG([-no-pie],
> > > [LDFLAGS="${LDFLAGS} -no-pie"
> > > export LDFLAGS])
> > > + AX_CHECK_COMPILE_FLAG([-fno-PIE],
> > > + [CFLAGS="${CFLAGS} -fno-PIE"
> > > + export CFLAGS])
> > > ;;
> > > *darwin*)
> > > # 27 November 2022: PMA only works on Intel.
> > > --
> > > 2.38.1
> > >
>
> --
>
> Sergei