mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [musl] Static linking is broken after creation of DT_TEXTREL segment
Date: Mon, 3 Feb 2020 05:32:51 +0100	[thread overview]
Message-ID: <20200203043251.GM2020@voyager> (raw)
In-Reply-To: <20200203031036.GL1663@brightrain.aerifal.cx>

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

  parent reply	other threads:[~2020-02-03  4:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 18:41 Андрей Аладьев
2020-01-29 19:19 ` Markus Wichmann
2020-01-29 19:38   ` Markus Wichmann
2020-01-29 20:48     ` Rich Felker
2020-01-29 20:08   ` Андрей Аладьев
2020-01-30 17:02     ` Markus Wichmann
2020-01-31  4:24       ` Rich Felker
2020-01-31 14:47         ` Markus Wichmann
2020-01-31 16:35           ` Rich Felker
2020-01-31 15:16       ` Андрей Аладьев
2020-01-31 16:40         ` Rich Felker
2020-01-31 17:51           ` Андрей Аладьев
2020-01-31 18:01             ` Rich Felker
2020-01-31 19:11               ` Андрей Аладьев
2020-02-03  3:10       ` Rich Felker
2020-02-03  4:05         ` Rich Felker
2020-02-03  4:32         ` Markus Wichmann [this message]
2020-02-03  4:40           ` Rich Felker
2020-01-29 20:53 ` Rich Felker
2020-01-29 21:10   ` Szabolcs Nagy
2020-01-29 21:35     ` Андрей Аладьев
2020-01-29 21:46       ` Rich Felker
2020-01-29 23:10         ` Андрей Аладьев
2020-01-29 23:20       ` Szabolcs Nagy
2020-01-29 21:14   ` Андрей Аладьев
2020-01-29 21:43     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200203043251.GM2020@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).