public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Tom Kacvinsky via Gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: How to tell if a ELF library/executable was built with -fpic versus -fPIC
Date: Tue, 04 Jan 2022 07:52:15 +0100	[thread overview]
Message-ID: <87mtkcgfhc.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAG_eJLfrgBdn9V+0SyCjJ2XZ7btnznL95=vhQTe+6Hg7hSzE1w@mail.gmail.com> (Tom Kacvinsky via Gcc-help's message of "Sun, 2 Jan 2022 11:06:31 -0500")

* Tom Kacvinsky via Gcc-help:

> Perhaps this belongs on the binutils list, but I'd like to know how if an ELF
> library/executable was built with -fpic versus -fPIC.  I know each makes PIC
> object code, with the difference being the size of the data model:
>
> -msmall-data (-fpic)
> -mlarge-data (-fPIC)
>
> but I have some shared libraries I am linking against such that I don't know
> which PIC option was used to build it.  Is there an ELF header I can check?

It depends on the the concrete target.  For a fully linked executable,
you'd have to disassemble it and check what is used for GOT access.  For
relocatable object files, you can look at the relocations.  There should
be an architecture-specific subset that can only handle a limited range,
and that set corresponds to -fpic.

There might be other options that affect the code model, with similar
consequences as the -fpic/-fPIC distinction.

Thanks,
Florian


      reply	other threads:[~2022-01-04  6:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-02 16:06 Tom Kacvinsky
2022-01-04  6:52 ` Florian Weimer [this message]

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=87mtkcgfhc.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).