From: Michal Suchánek <hidden> Date: 2018-10-31 17:50:35
On Wed, 31 Oct 2018 18:20:56 +0100
Florian Weimer [off-list ref] wrote:
We tried to use Go to build PIE binaries, and while the Go toolchain
is definitely not ready (it produces text relocations and problematic
relocations in general), it exposed what could be an accidental
userspace ABI change.
With our 4.10-derived kernel, PIE binaries are mapped below 4 GiB, so
relocations like R_PPC64_ADDR16_HA work:
...
There are fewer mappings because the loader detects a relocation
overflow and aborts (“error while loading shared libraries:
R_PPC64_ADDR16_HA reloc at 0x0000000120f0983c for symbol `' out of
range”), so I had to recover the mappings externally. Disabling ASLR
does not help.
...
And it needs to be built with:
go build -ldflags=-extldflags=-pie extld.go
I'm not entirely sure what to make of this, but I'm worried that this
could be a regression that matters to userspace.
I encountered the same when trying to build go on ppc64le. I am not
familiar with the internals so I just let it be.
It does not seem to matter to any other userspace. Maybe it would be
good idea to generate 64bit relocations on 64bit targets?
Thanks
Michal
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2018-11-01 03:55:40
Hi Florian,
Florian Weimer [off-list ref] writes:
We tried to use Go to build PIE binaries, and while the Go toolchain is
definitely not ready (it produces text relocations and problematic
relocations in general), it exposed what could be an accidental
userspace ABI change.
With our 4.10-derived kernel, PIE binaries are mapped below 4 GiB, so
relocations like R_PPC64_ADDR16_HA work:
21f00000-220d0000 r-xp 00000000 fd:00 36593493 /root/extld
220d0000-220e0000 r--p 001c0000 fd:00 36593493 /root/extld
220e0000-22100000 rw-p 001d0000 fd:00 36593493 /root/extld
...
With a 4.18-derived kernel (with the hashed mm), we get this instead:
120e60000-121030000 rw-p 00000000 fd:00 102447141 /root/extld
121030000-121060000 rw-p 001c0000 fd:00 102447141 /root/extld
121060000-121080000 rw-p 00000000 00:00 0
I assume that's caused by:
47ebb09d5485 ("powerpc: move ELF_ET_DYN_BASE to 4GB / 4MB")
Which did roughly:
-#define ELF_ET_DYN_BASE 0x20000000
+#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \
+ 0x100000000UL)
And went into 4.13.
...
I'm not entirely sure what to make of this, but I'm worried that this
could be a regression that matters to userspace.
It was a deliberate change, and it seemed to not break anything so we
merged it. But obviously we didn't test widely enough.
So I guess it clearly can matter to userspace, and it used to work, so
therefore it is a regression.
But at the same time we haven't had any other reports of breakage, so is
this somehow specific to something Go is doing? Or did we just get lucky
up until now? Or is no one actually testing on Power? ;)
cheers
From: Alan Modra <hidden> Date: 2018-11-01 06:49:18
On Thu, Nov 01, 2018 at 02:55:34PM +1100, Michael Ellerman wrote:
Hi Florian,
Florian Weimer [off-list ref] writes:
quoted
We tried to use Go to build PIE binaries, and while the Go toolchain is
definitely not ready (it produces text relocations and problematic
relocations in general), it exposed what could be an accidental
userspace ABI change.
With our 4.10-derived kernel, PIE binaries are mapped below 4 GiB, so
relocations like R_PPC64_ADDR16_HA work:
21f00000-220d0000 r-xp 00000000 fd:00 36593493 /root/extld
220d0000-220e0000 r--p 001c0000 fd:00 36593493 /root/extld
220e0000-22100000 rw-p 001d0000 fd:00 36593493 /root/extld
...
quoted
With a 4.18-derived kernel (with the hashed mm), we get this instead:
120e60000-121030000 rw-p 00000000 fd:00 102447141 /root/extld
121030000-121060000 rw-p 001c0000 fd:00 102447141 /root/extld
121060000-121080000 rw-p 00000000 00:00 0
I assume that's caused by:
47ebb09d5485 ("powerpc: move ELF_ET_DYN_BASE to 4GB / 4MB")
Which did roughly:
-#define ELF_ET_DYN_BASE 0x20000000
+#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \
+ 0x100000000UL)
And went into 4.13.
quoted
...
I'm not entirely sure what to make of this, but I'm worried that this
could be a regression that matters to userspace.
It was a deliberate change, and it seemed to not break anything so we
merged it. But obviously we didn't test widely enough.
So I guess it clearly can matter to userspace, and it used to work, so
therefore it is a regression.
But at the same time we haven't had any other reports of breakage, so is
this somehow specific to something Go is doing? Or did we just get lucky
up until now? Or is no one actually testing on Power? ;)
Mapping PIEs above 4G should be fine. It works for gcc C and C++
after all. The problem is that ppc64le Go is generating code not
suitable for a PIE. Dynamic text relocations are evidence of non-PIC
object files.
Quoting Lynn Boger [off-list ref]:
"When building a pie binary with golang, they should be using
-buildmode=pie and not just pass -pie to the linker".
--
Alan Modra
Australia Development Lab, IBM
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2018-11-02 09:41:59
Alan Modra [off-list ref] writes:
On Thu, Nov 01, 2018 at 02:55:34PM +1100, Michael Ellerman wrote:
quoted
Hi Florian,
Florian Weimer [off-list ref] writes:
quoted
We tried to use Go to build PIE binaries, and while the Go toolchain is
definitely not ready (it produces text relocations and problematic
relocations in general), it exposed what could be an accidental
userspace ABI change.
With our 4.10-derived kernel, PIE binaries are mapped below 4 GiB, so
relocations like R_PPC64_ADDR16_HA work:
21f00000-220d0000 r-xp 00000000 fd:00 36593493 /root/extld
220d0000-220e0000 r--p 001c0000 fd:00 36593493 /root/extld
220e0000-22100000 rw-p 001d0000 fd:00 36593493 /root/extld
...
quoted
With a 4.18-derived kernel (with the hashed mm), we get this instead:
120e60000-121030000 rw-p 00000000 fd:00 102447141 /root/extld
121030000-121060000 rw-p 001c0000 fd:00 102447141 /root/extld
121060000-121080000 rw-p 00000000 00:00 0
I assume that's caused by:
47ebb09d5485 ("powerpc: move ELF_ET_DYN_BASE to 4GB / 4MB")
Which did roughly:
-#define ELF_ET_DYN_BASE 0x20000000
+#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \
+ 0x100000000UL)
And went into 4.13.
quoted
...
I'm not entirely sure what to make of this, but I'm worried that this
could be a regression that matters to userspace.
It was a deliberate change, and it seemed to not break anything so we
merged it. But obviously we didn't test widely enough.
So I guess it clearly can matter to userspace, and it used to work, so
therefore it is a regression.
But at the same time we haven't had any other reports of breakage, so is
this somehow specific to something Go is doing? Or did we just get lucky
up until now? Or is no one actually testing on Power? ;)
Mapping PIEs above 4G should be fine. It works for gcc C and C++
after all. The problem is that ppc64le Go is generating code not
suitable for a PIE. Dynamic text relocations are evidence of non-PIC
object files.
Quoting Lynn Boger [off-list ref]:
"When building a pie binary with golang, they should be using
-buildmode=pie and not just pass -pie to the linker".
Thanks Alan.
So this isn't a kernel bug per se, but the the old behaviour falls in
the category of "shouldn't have worked but did by accident", and so the
question is just how wide spread is the userspace breakage.
At least so far it seems not very wide spread, so we'll leave things as
they are for now. As Florian said we can always add a personality flag
in future if we need to.
cheers