public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc-bugzilla at mkarcher dot dialup.fu-berlin.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/94504] On powerpc, -ffunction-sections -fdata-sections is not as effective as expected for PIE executables.
Date: Tue, 07 Apr 2020 15:09:02 +0000	[thread overview]
Message-ID: <bug-94504-4-Pe2HS3xWNH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94504-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94504

--- Comment #3 from Michael Karcher <gcc-bugzilla at mkarcher dot dialup.fu-berlin.de> ---
(In reply to Richard Biener from comment #2)
> Huh, looking at the assembly & the object file this seems to be fully a linker
> issue who seems to be responsible for building the GOT.  I suggest to move
> this over to sourceware.  Alan?

I'm not so sure about this. I think it might actually be a limitation of ELF on
ppc32:

If I compare the code generated by gcc on ppc32, gcc does output a GOT fragment
in the .got2 section that references all globals that are used in the current
object:

$ objdump -r -j .got2 bla32.o

bla32.o:     file format elf32-powerpc

RELOCATION RECORDS FOR [.got2]:
OFFSET   TYPE              VALUE
00000000 R_PPC_ADDR32      fptr
00000004 R_PPC_ADDR32      x

This section can not be elided, because it is referenced from main:

$ objdump -r -j .text.main bla32.o

bla32.o:     file format elf32-powerpc

RELOCATION RECORDS FOR [.text.main]:
OFFSET   TYPE              VALUE
00000022 R_PPC_REL16_HA    .got2+0x00008006
00000026 R_PPC_REL16_LO    .got2+0x0000800a

The linker has no obvious way to detect which GOT slots are actually used
inside main, because the offset(s) of the slot(s) inside .got2 used by main are
hardcoded inside main.

On the other hand, on ppc64, there is no GOT fragment generated by the
compiler, but instead the compiler just asks the linker to create a GOT slot
and fill in the necessary information:

$ objdump -r -j .text.main bla64.o

bla64.o:     file format elf64-powerpc

RELOCATION RECORDS FOR [.text.main]:
OFFSET           TYPE              VALUE
000000000000000e R_PPC64_TOC16_HA  x
0000000000000012 R_PPC64_TOC16_LO  x

  parent reply	other threads:[~2020-04-07 15:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 18:08 [Bug target/94504] New: " gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
2020-04-07  6:47 ` [Bug target/94504] " rguenth at gcc dot gnu.org
2020-04-07  7:04 ` rguenth at gcc dot gnu.org
2020-04-07 15:09 ` gcc-bugzilla at mkarcher dot dialup.fu-berlin.de [this message]
2020-04-07 17:14 ` rguenther at suse dot de
2020-04-07 21:28 ` [Bug target/94504] On powerpc, -ffunction-sections -fdata-sections is not as effective as expected for non-PIE executables gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
2020-04-13  3:49 ` [Bug target/94504] On powerpc, -ffunction-sections -fdata-sections is not as effective as expected for PIE and PIC amodra at gmail dot com
2020-04-13  6:53 ` glaubitz at physik dot fu-berlin.de

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=bug-94504-4-Pe2HS3xWNH@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).