public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: vincent Dupaquis <v.dupaquis@trusted-objects.com>
To: <gcc-help@gcc.gnu.org>
Subject: Question related to -fPIC behaviour across architectures
Date: Tue, 3 May 2022 10:26:25 +0200	[thread overview]
Message-ID: <7038357f-02af-0bcd-f156-73851c3227b3@trusted-objects.com> (raw)
In-Reply-To: <CAH9OHLJ_EnbTA6Ga8w77tGEijjHYadB8s_1dk4TLUH5oCGS5Ew@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1387 bytes --]

Hello,

I am using -fPIC option on several architectures, and have experienced 
some strange differences in behavior over 2 aspects :

     - Call of routines

     - Access to constants (eg. constant strings, constant tables, 
larger to fit into one single instruction).

When compiling with -fPIC on an arm platform (I am using Cortex-Mx), the 
jumps and calls are all relative, and constant access are also relative 
if you are cautious enough. You may even end-up having the compiler not 
needing the GOT. Bottom line, for me -fPIC on ARM means portable and 
really Position Independant Code. (I am using GCC 10.3).

When compiling with -fPIC on a xtensa platform, the compiler generates 
CALLX instructions, which effectively make an access at an absolute 
address. The same issue appears about the constants, which are accessed 
at the address you compiled your binary for, which is not the definition 
I have (and have experienced on ARM platforms). (I am using in this case 
8.4).

When NOT specifying -fPIC on a xtensa platform, the compiler generates 
CALL instructions, which are relative calls, and which is the base for 
me for having a portable/relocable executable.

My questions are :

- Did I miss anything ?

- Is there somewhere a common definition of what mean PIC for the 
different architectures ?

Regards,

Vincent.



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  parent reply	other threads:[~2022-05-03  8:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 22:43 Compile GCC using only tools isolated from host environment Benjamin Lovy
2022-03-15  7:19 ` Xi Ruoyao
2022-03-16 16:06   ` Benjamin Lovy
2022-03-15  8:46 ` Jonathan Wakely
2022-05-03  8:26 ` vincent Dupaquis [this message]
2022-05-03 10:24   ` Question related to -fPIC behaviour across architectures Xi Ruoyao
2022-05-03 13:29     ` vincent Dupaquis
2022-05-03 14:29   ` Florian Weimer
2022-05-03 15:45     ` vincent Dupaquis

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=7038357f-02af-0bcd-f156-73851c3227b3@trusted-objects.com \
    --to=v.dupaquis@trusted-objects.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).