Gentoo Archives: gentoo-user

From: Walter Dnes <waltdnes@××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] gcc 6 PIE use flag
Date: Tue, 09 May 2017 18:30:27
Message-Id: 20170509182916.GA19176@waltdnes.org
In Reply to: [gentoo-user] gcc 6 PIE use flag by Adam Carter
1 On Mon, May 08, 2017 at 08:46:54AM +1000, Adam Carter wrote
2 > Since an update to the default USE flags on gcc 6 turned on PIE and SSP,
3 > i'm getting these errors;
4 >
5 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
6 > atof-generic.o: relocation R_X86_64_32 against `.rodata' can not be used
7 > when making a shared object; recompile with -fPIC
8 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
9 > dw2gencfi.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be
10 > used when making a shared object; recompile with -fPIC
11 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
12 > frags.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used
13 > when making a shared object; recompile with -fPIC
14 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
15 > messages.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used
16 > when making a shared object; recompile with -fPIC
17 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
18 > subsegs.o: relocation R_X86_64_32 against `.rodata' can not be used when
19 > making a shared object; recompile with -fPIC
20 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
21 > symbols.o: relocation R_X86_64_32S against symbol `_sch_toupper' can not be
22 > used when making a shared object; recompile with -fPIC
23 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
24 > atof-ieee.o: relocation R_X86_64_32S against `.rodata' can not be used when
25 > making a shared object; recompile with -fPIC
26 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
27 > symbols.o: warning: relocation against `strlen@@GLIBC_2.2.5' in readonly
28 > section `.text'
29 > /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld:
30 > final link failed: Nonrepresentable section on output
31 > collect2: error: ld returned 1 exit status
32 >
33 > If I add -fPIC to CFLAGS it will compile. Interestingly some packages (eg
34 > PHP) will compile without the -fPIC. Also the man page says; "This option
35 > makes a difference on AArch64, m68k, PowerPC and SPARC:, whereas i'm
36 > running amd64.
37 >
38 > What's going on here?
39
40 It's a feature, not a bug. <G> There's a news item being worked on in
41 the Gentoo dev list. I'd normally just link to a mail archive, but it's
42 too new to have been archived yet. Here's a copy of the proposed news
43 item. Note the example error message about relocation against .rodata
44
45 #######################################################################
46 Title: GCC 6 defaults to USE="pie ssp"
47 Author: Matthias Maier <tamiko@g.o>
48 Content-Type: text/plain
49 Posted: 2017-05-07
50 Revision: 1
51 News-Item-Format: 1.0
52 Display-If-Installed: >=sys-devel/gcc-6.3.0
53 Display-If-Keyword: amd64
54
55 In Gentoo, several GCC features can be default disabled or enabled
56 via use-flags of sys-devel/gcc. Starting with gcc-4.8.3 we have already
57 enabled default SSP [1]. Since the PIE patchset for default position
58 independent executable support was integrated upstream [2,3], starting
59 with gcc-6.3 we are also enabling PIE by default (via a default-enabled
60 use-flag pie) in regular (non-hardened) profiles.
61
62 [Additionally, following Gentoo policies, the default-off use-flags
63 nopie (only present in Hardened) and nossp are replaced starting with
64 gcc-6 by default-on use-flags pie and ssp.]
65
66 Be advised that switching from an older version to GCC 6 will enable the
67 PIE feature by default. This should not cause many problems, but it may
68 be necessary to recompile parts of your userland. An indicator are
69 linker errors of the form [4]
70
71 relocation R_X86_64_32 against `.rodata.str1.1' can not be used when
72 making a shared object; recompile with -fPIC
73
74 [1] https://www.gentoo.org/support/news-items/2014-06-15-gcc48_ssp.html
75 [2] https://gcc.gnu.org/gcc-6/changes.html
76 [3] A big thanks to all developers and members of the Gentoo community that
77 made upstreaming the pie patchset and other hardening options possible!
78 [4] https://bugs.gentoo.org/617698
79 #######################################################################
80
81
82 --
83 Walter Dnes <waltdnes@××××××××.org>
84 I don't run "desktop environments"; I run useful applications

Replies

Subject Author
[gentoo-user] [OT] Horrible English Peter Humphrey <peter@××××××××××××.uk>
Re: [gentoo-user] gcc 6 PIE use flag Adam Carter <adamcarter3@×××××.com>