Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 3 Feb 2020 05:32:51 +0100
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Subject: Re: Static linking is broken after creation of DT_TEXTREL
 segment

On Sun, Feb 02, 2020 at 10:10:36PM -0500, Rich Felker wrote:
> I'll probably end up having mcm pass --with-pic to GCC's top-level
> configure, but I see this will be picked up by some other libs like
> libcc1, which oddly aren't failing for the same reason. Any idea why?

I'd guess they don't use assembly, or at least their assembly does not
try to access global symbols. I haven't looked at the source though. And
I won't until the afternoon at least.

> Is this the right fix for mcm? What could/should be done to unbreak
> gmp with default-pie toolchains? Is it a bug in the version of libtool
> they're using or a bug in gmp?
>
> Rich

The problem is with the assumptions of GMP. And I really don't know how
to fix those. GMP's build system generates a dynamic and a static
library, and assumes that the static library does not need to be PIC.
With the advent of static-pie, this assumption is subverted. But how to
deal with this generally? Many libraries assume the static one does not
need PIC. And while PIC has little to no overhead on AMD64, other
architectures are not so forgiving. For example, on PowerPC, you need to
set up a GOT pointer first, which requires spilling the link register,
calling the next instruction so you can get its address, adding the
offset to the GOT to that, then adding the GOT relocation to that. So
you get the non-PIC code:

    lis rX,sym@ha
    addi rX,rX,sym@l

turning into the PIC code:

    mflr r0
    bcl 20,31,1f
1:  mflr rX
    addis rX,rX,(_GLOBAL_OFFSET_TABLE_ - 1b)@ha
    addi rX,rX,(_GLOBAL_OFFSET_TABLE_ - 1b)@l
    mtlr r0
    lwz rX,sym@got(rX)

(Wait, can sym@got exceed 32k? Then that last instruction turns into two
instructions again.)

It would be hard to argue that the latter is as efficient as the former,
is my point.

In case of GMP, I would argue they can add a test to determine if the
toolchain generates static-pie, and turn on PIC by default if so. No
clue if upstream will like that, though.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.