public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/2] sparc: Fix .udiv plt on libc
  2017-03-16 13:43 [PATCH 1/2] Build divdi3 only for architecture that required it Adhemerval Zanella
@ 2017-03-16 13:43 ` Adhemerval Zanella
  2017-03-16 14:45   ` Florian Weimer
  2017-03-16 13:58 ` [PATCH 1/2] Build divdi3 only for architecture that required it Andreas Schwab
  1 sibling, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2017-03-16 13:43 UTC (permalink / raw)
  To: libc-alpha

With the removal of divdi3 object from sparcv9-linux-gnu build, its
definition came from libgcc and its functions internall calls .udiv.
Since glibc also exports these symbols for compatibility reasons, it
will end up creating PLT calls internally in libc.so.

To avoid it, this patch uses the linker option --wrap to replace all
the internal libc.so .udiv calls to the wrapper __wrap_.udiv. Along
with strong alias in the udiv implementations, it makes linker do
local calls.

Checked on sparcv9-linux-gnu.

	* sysdeps/sparc/sparc32/Makefile (libc.so-gnulib): New rule.
	* sysdeps/sparc/sparc32/sparcv8/udiv.S (.udiv): Make a strong_alias
	to __wrap_.udiv.
	* sysdeps/sparc/sparc32/sparcv9/udiv.S (.udiv): Likewise.
	* sysdeps/sparc/sparc32/udiv.S (.udiv): Likewise.
---
 ChangeLog                            | 6 ++++++
 sysdeps/sparc/sparc32/Makefile       | 6 ++++++
 sysdeps/sparc/sparc32/sparcv8/udiv.S | 1 +
 sysdeps/sparc/sparc32/sparcv9/udiv.S | 1 +
 sysdeps/sparc/sparc32/udiv.S         | 1 +
 5 files changed, 15 insertions(+)

diff --git a/sysdeps/sparc/sparc32/Makefile b/sysdeps/sparc/sparc32/Makefile
index da20589..6d2a196 100644
--- a/sysdeps/sparc/sparc32/Makefile
+++ b/sysdeps/sparc/sparc32/Makefile
@@ -47,3 +47,9 @@ $(divrem:%=$(sysdep_dir)/sparc/sparc32/%.S): $(sysdep_dir)/sparc/sparc32/divrem.
 	mv -f $@-tmp $@
 
 sysdep-realclean := $(sysdep-realclean) $(divrem:%=sysdeps/sparc/sparc32/%.S)
+
+# libgcc __divdi3 and __moddi3 use .udiv and since it is also exported by
+# libc.so linker will create PLTs for the symbol.  To avoid it we strong alias
+# the exported libc one to __wrap_.udiv and use linker option --wrap to make any
+# call to .udiv to call the wrapper symbol.
+libc.so-gnulib += -Wl,--wrap=.udiv
diff --git a/sysdeps/sparc/sparc32/sparcv8/udiv.S b/sysdeps/sparc/sparc32/sparcv8/udiv.S
index d719543..e9cab4e 100644
--- a/sysdeps/sparc/sparc32/sparcv8/udiv.S
+++ b/sysdeps/sparc/sparc32/sparcv8/udiv.S
@@ -13,3 +13,4 @@ ENTRY(.udiv)
 	 udiv	%o0, %o1, %o0
 
 END(.udiv)
+strong_alias (.udiv, __wrap_.udiv)
diff --git a/sysdeps/sparc/sparc32/sparcv9/udiv.S b/sysdeps/sparc/sparc32/sparcv9/udiv.S
index de79899..368f85e 100644
--- a/sysdeps/sparc/sparc32/sparcv9/udiv.S
+++ b/sysdeps/sparc/sparc32/sparcv9/udiv.S
@@ -15,3 +15,4 @@ ENTRY(.udiv)
 	 udiv		%o0, %o1, %o0
 
 END(.udiv)
+strong_alias (.udiv, __wrap_.udiv)
diff --git a/sysdeps/sparc/sparc32/udiv.S b/sysdeps/sparc/sparc32/udiv.S
index 8dfff66..ade0afd 100644
--- a/sysdeps/sparc/sparc32/udiv.S
+++ b/sysdeps/sparc/sparc32/udiv.S
@@ -344,3 +344,4 @@ LOC(got_result):
 	mov %o2, %o0
 
 END(.udiv)
+strong_alias (.udiv, __wrap_.udiv)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] Build divdi3 only for architecture that required it
@ 2017-03-16 13:43 Adhemerval Zanella
  2017-03-16 13:43 ` [PATCH 2/2] sparc: Fix .udiv plt on libc Adhemerval Zanella
  2017-03-16 13:58 ` [PATCH 1/2] Build divdi3 only for architecture that required it Andreas Schwab
  0 siblings, 2 replies; 13+ messages in thread
From: Adhemerval Zanella @ 2017-03-16 13:43 UTC (permalink / raw)
  To: libc-alpha

As noted in [1], divdi3 object is only exported in a handful ABIs
(i386, m68k, powerpc32, s390-32, and ia64), however it is built
for all current architectures regardless.

This patch refact the make rules for this object to so only the
aforementioned architectures that actually require it builds it.

Also, to avoid internal PLT calls to the exported symbol from the
module, glibc uses an internal header (symbol-hacks.h) which is
unrequired (and in fact breaks the build for architectures that
intend to get symbol definitions from libgcc.a).  The patch also
changes it to create its own header (divdi3-symbol-hacks.h) and
adjust the architectures that require it accordingly.

I checked the build/check (with run-built-tests=no) on the
following architectures (which I think must cover all supported
ABI/builds) using GCC 6.3:

aarch64-linux-gnu
alpha-linux-gnu
arm-linux-gnueabihf
hppa-linux-gnu
ia64-linux-gnu
m68k-linux-gnu
microblaze-linux-gnu
mips64-n32-linux-gnu
mips-linux-gnu
mips64-linux-gnu
nios2-linux-gnu
powerpc-linux-gnu
powerpc-linux-gnu-power4
powerpc64-linux-gnu
powerpc64le-linux-gnu
s390x-linux-gnu
s390-linux-gnu
sh4-linux-gnu
sh4-linux-gnu-soft
sparc64-linux-gnu
sparcv9-linux-gnu
tilegx-linux-gnu
tilegx-linux-gnu-32
tilepro-linux-gnu
x86_64-linux-gnu
x86_64-linux-gnu-x32
i686-linux-gnu

I only saw one regression on sparcv9-linux-gnu (extra PLT call to
.udiv) which I address in next patch in the set.  It also correctly
build SH with GCC 7.0.1 (without any regression from c89721e25d).

[1] https://sourceware.org/ml/libc-alpha/2017-03/msg00243.html

	* sysdeps/i386/symbol-hacks.h: New file.
	* sysdeps/m68k/symbol-hacks.h: New file.
	* sysdeps/powerpc/powerpc32/symbol-hacks.h: New file.
	* sysdeps/s390/s390-32/symbol-hacks.h: New file.
	* sysdeps/unix/sysv/linux/i386/Makefile
	[$(subdir) = csu] (sysdep_routines): New rule: divdi3 object.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/m68k/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/wordsize-32/Makefile: Remove file.
	* sysdeps/wordsize-32/symbol-hacks.h: Definitions move to ...
	* sysdeps/wordsize-32/divdi3-symbol-hacks.h: ... here.
---
 ChangeLog                                          | 26 ++++++++++++++++++++++
 sysdeps/i386/symbol-hacks.h                        | 21 +++++++++++++++++
 sysdeps/m68k/symbol-hacks.h                        | 21 +++++++++++++++++
 sysdeps/powerpc/powerpc32/symbol-hacks.h           | 21 +++++++++++++++++
 sysdeps/s390/s390-32/symbol-hacks.h                | 19 ++++++++++++++++
 sysdeps/unix/sysv/linux/i386/Makefile              |  5 +++++
 sysdeps/unix/sysv/linux/m68k/Makefile              |  5 +++++
 sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile |  8 +++++++
 sysdeps/unix/sysv/linux/s390/s390-32/Makefile      |  8 +++++++
 sysdeps/wordsize-32/Makefile                       |  7 ------
 .../{symbol-hacks.h => divdi3-symbol-hacks.h}      |  8 +++----
 11 files changed, 138 insertions(+), 11 deletions(-)
 create mode 100644 sysdeps/i386/symbol-hacks.h
 create mode 100644 sysdeps/m68k/symbol-hacks.h
 create mode 100644 sysdeps/powerpc/powerpc32/symbol-hacks.h
 create mode 100644 sysdeps/s390/s390-32/symbol-hacks.h
 delete mode 100644 sysdeps/wordsize-32/Makefile
 rename sysdeps/wordsize-32/{symbol-hacks.h => divdi3-symbol-hacks.h} (89%)

diff --git a/sysdeps/i386/symbol-hacks.h b/sysdeps/i386/symbol-hacks.h
new file mode 100644
index 0000000..36a13c8
--- /dev/null
+++ b/sysdeps/i386/symbol-hacks.h
@@ -0,0 +1,21 @@
+/* Hacks needed for symbol manipulation.  i386 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
+
+#include_next "symbol-hacks.h"
diff --git a/sysdeps/m68k/symbol-hacks.h b/sysdeps/m68k/symbol-hacks.h
new file mode 100644
index 0000000..e449d29
--- /dev/null
+++ b/sysdeps/m68k/symbol-hacks.h
@@ -0,0 +1,21 @@
+/* Hacks needed for symbol manipulation.  m68k version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
+
+#include_next "symbol-hacks.h"
diff --git a/sysdeps/powerpc/powerpc32/symbol-hacks.h b/sysdeps/powerpc/powerpc32/symbol-hacks.h
new file mode 100644
index 0000000..dbb3141
--- /dev/null
+++ b/sysdeps/powerpc/powerpc32/symbol-hacks.h
@@ -0,0 +1,21 @@
+/* Hacks needed for symbol manipulation.  powerpc version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
+
+#include_next "symbol-hacks.h"
diff --git a/sysdeps/s390/s390-32/symbol-hacks.h b/sysdeps/s390/s390-32/symbol-hacks.h
new file mode 100644
index 0000000..82fb0f6
--- /dev/null
+++ b/sysdeps/s390/s390-32/symbol-hacks.h
@@ -0,0 +1,19 @@
+/* Hacks needed for symbol manipulation.  s390 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index 6aac0df..4080b8c 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -26,6 +26,11 @@ endif
 
 ifeq ($(subdir),csu)
 sysdep-dl-routines += sysdep
+ifeq (yes,$(build-shared))
+sysdep_routines += divdi3
+shared-only-routines += divdi3
+CPPFLAGS-divdi3.c = -Din_divdi3_c
+endif
 endif
 
 ifeq ($(subdir),nptl)
diff --git a/sysdeps/unix/sysv/linux/m68k/Makefile b/sysdeps/unix/sysv/linux/m68k/Makefile
index 5c50ce6..ce1f696 100644
--- a/sysdeps/unix/sysv/linux/m68k/Makefile
+++ b/sysdeps/unix/sysv/linux/m68k/Makefile
@@ -4,6 +4,11 @@ m68k-syntax-flag = -DMOTOROLA_SYNTAX
 
 ifeq ($(subdir),csu)
 sysdep_routines += m68k-helpers
+ifeq (yes,$(build-shared))
+sysdep_routines += divdi3
+shared-only-routines += divdi3
+CPPFLAGS-divdi3.c = -Din_divdi3_c
+endif
 endif
 
 ifeq ($(subdir),misc)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
index 3d6c150..1f45659 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
@@ -1,2 +1,10 @@
 # See Makeconfig regarding the use of default-abi.
 default-abi := 32
+
+ifeq ($(subdir),csu)
+ifeq (yes,$(build-shared))
+sysdep_routines += divdi3
+shared-only-routines += divdi3
+CPPFLAGS-divdi3.c = -Din_divdi3_c
+endif
+endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
index da3b3c7..fd8cf92 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
@@ -21,3 +21,11 @@ endif
 ifeq ($(subdir),stdlib)
 sysdep_routines += __makecontext_ret
 endif
+
+ifeq ($(subdir),csu)
+ifeq (yes,$(build-shared))
+sysdep_routines += divdi3
+shared-only-routines += divdi3
+CPPFLAGS-divdi3.c = -Din_divdi3_c
+endif
+endif
diff --git a/sysdeps/wordsize-32/Makefile b/sysdeps/wordsize-32/Makefile
deleted file mode 100644
index 82beac4..0000000
--- a/sysdeps/wordsize-32/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-ifeq ($(subdir),csu)
-ifeq (yes,$(build-shared))
-sysdep_routines += divdi3
-shared-only-routines += divdi3
-CPPFLAGS-divdi3.c = -Din_divdi3_c
-endif
-endif
diff --git a/sysdeps/wordsize-32/symbol-hacks.h b/sysdeps/wordsize-32/divdi3-symbol-hacks.h
similarity index 89%
rename from sysdeps/wordsize-32/symbol-hacks.h
rename to sysdeps/wordsize-32/divdi3-symbol-hacks.h
index 0aec1e0..6c90cb7 100644
--- a/sysdeps/wordsize-32/symbol-hacks.h
+++ b/sysdeps/wordsize-32/divdi3-symbol-hacks.h
@@ -1,4 +1,4 @@
-/* Hacks needed for symbol manipulation.
+/* Hacks needed for divdi3 symbol manipulation.
    Copyright (C) 2004-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,13 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include_next "symbol-hacks.h"
-
 /* A very dirty trick: gcc emits references to __divdi3, __udivdi3,
    __moddi3, and __umoddi3.  These functions are exported and
    therefore we get PLTs.  Unnecessarily so.  Changing gcc is a big
    task which might not be worth it so we play tricks with the
-   assembler.  */
+   assembler.
+   Note: in_divdi3_c is only used to avoid symbol alias on divdi3
+   build itself.  */
 #if !defined __ASSEMBLER__ && !defined in_divdi3_c && IS_IN (libc) && defined SHARED
 asm ("__divdi3 = __divdi3_internal");
 asm ("__udivdi3 = __udivdi3_internal");
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-03-16 13:43 [PATCH 1/2] Build divdi3 only for architecture that required it Adhemerval Zanella
  2017-03-16 13:43 ` [PATCH 2/2] sparc: Fix .udiv plt on libc Adhemerval Zanella
@ 2017-03-16 13:58 ` Andreas Schwab
  2017-03-16 17:00   ` Adhemerval Zanella
  1 sibling, 1 reply; 13+ messages in thread
From: Andreas Schwab @ 2017-03-16 13:58 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Mär 16 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> diff --git a/sysdeps/s390/s390-32/symbol-hacks.h b/sysdeps/s390/s390-32/symbol-hacks.h
> new file mode 100644
> index 0000000..82fb0f6
> --- /dev/null
> +++ b/sysdeps/s390/s390-32/symbol-hacks.h
> @@ -0,0 +1,19 @@
> +/* Hacks needed for symbol manipulation.  s390 version.
> +   Copyright (C) 2017 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>

No include_next?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] sparc: Fix .udiv plt on libc
  2017-03-16 13:43 ` [PATCH 2/2] sparc: Fix .udiv plt on libc Adhemerval Zanella
@ 2017-03-16 14:45   ` Florian Weimer
  2017-03-16 16:59     ` Adhemerval Zanella
  0 siblings, 1 reply; 13+ messages in thread
From: Florian Weimer @ 2017-03-16 14:45 UTC (permalink / raw)
  To: libc-alpha

On 03/16/2017 02:43 PM, Adhemerval Zanella wrote:
> To avoid it, this patch uses the linker option --wrap to replace all
> the internal libc.so .udiv calls to the wrapper __wrap_.udiv. Along
> with strong alias in the udiv implementations, it makes linker do
> local calls.

I think we already use a different mechanism for a similar purpose, via 
sysdeps/generic/symbol-hacks.h.  Maybe it's possible to reuse that?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] sparc: Fix .udiv plt on libc
  2017-03-16 14:45   ` Florian Weimer
@ 2017-03-16 16:59     ` Adhemerval Zanella
  2017-03-27 15:33       ` Adhemerval Zanella
  0 siblings, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2017-03-16 16:59 UTC (permalink / raw)
  To: libc-alpha



On 16/03/2017 11:45, Florian Weimer wrote:
> On 03/16/2017 02:43 PM, Adhemerval Zanella wrote:
>> To avoid it, this patch uses the linker option --wrap to replace all
>> the internal libc.so .udiv calls to the wrapper __wrap_.udiv. Along
>> with strong alias in the udiv implementations, it makes linker do
>> local calls.
> 
> I think we already use a different mechanism for a similar purpose, via sysdeps/generic/symbol-hacks.h.  Maybe it's possible to reuse that?
> 
> Thanks,
> Florian

The problem is now that divdi3 is not provided by glibc anymore we can't
use the same trick since __divdi3 and __moddi3 will be provided by libgcc.
Another way to actually redefine .udiv is to either still keep using divdi3
for sparc32 .

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-03-16 13:58 ` [PATCH 1/2] Build divdi3 only for architecture that required it Andreas Schwab
@ 2017-03-16 17:00   ` Adhemerval Zanella
       [not found]     ` <af83ffde-83d3-d7d1-d45e-7c379b7e7123@linaro.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2017-03-16 17:00 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha



On 16/03/2017 10:58, Andreas Schwab wrote:
> On Mär 16 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> 
>> diff --git a/sysdeps/s390/s390-32/symbol-hacks.h b/sysdeps/s390/s390-32/symbol-hacks.h
>> new file mode 100644
>> index 0000000..82fb0f6
>> --- /dev/null
>> +++ b/sysdeps/s390/s390-32/symbol-hacks.h
>> @@ -0,0 +1,19 @@
>> +/* Hacks needed for symbol manipulation.  s390 version.
>> +   Copyright (C) 2017 Free Software Foundation, Inc.
>> +   This file is part of the GNU C Library.
>> +
>> +   The GNU C Library is free software; you can redistribute it and/or
>> +   modify it under the terms of the GNU Lesser General Public
>> +   License as published by the Free Software Foundation; either
>> +   version 2.1 of the License, or (at your option) any later version.
>> +
>> +   The GNU C Library is distributed in the hope that it will be useful,
>> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> +   Lesser General Public License for more details.
>> +
>> +   You should have received a copy of the GNU Lesser General Public
>> +   License along with the GNU C Library; if not, see
>> +   <http://www.gnu.org/licenses/>.  */
>> +
>> +#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
> 
> No include_next?
> 
> Andreas.
> 

Right, it is missing.  I will add it.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] sparc: Fix .udiv plt on libc
  2017-03-16 16:59     ` Adhemerval Zanella
@ 2017-03-27 15:33       ` Adhemerval Zanella
  0 siblings, 0 replies; 13+ messages in thread
From: Adhemerval Zanella @ 2017-03-27 15:33 UTC (permalink / raw)
  To: libc-alpha



On 16/03/2017 13:59, Adhemerval Zanella wrote:
> 
> 
> On 16/03/2017 11:45, Florian Weimer wrote:
>> On 03/16/2017 02:43 PM, Adhemerval Zanella wrote:
>>> To avoid it, this patch uses the linker option --wrap to replace all
>>> the internal libc.so .udiv calls to the wrapper __wrap_.udiv. Along
>>> with strong alias in the udiv implementations, it makes linker do
>>> local calls.
>>
>> I think we already use a different mechanism for a similar purpose, via sysdeps/generic/symbol-hacks.h.  Maybe it's possible to reuse that?
>>
>> Thanks,
>> Florian
> 
> The problem is now that divdi3 is not provided by glibc anymore we can't
> use the same trick since __divdi3 and __moddi3 will be provided by libgcc.
> Another way to actually redefine .udiv is to either still keep using divdi3
> for sparc32 .
> 

Any more impeding remark about this patch?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
       [not found]     ` <af83ffde-83d3-d7d1-d45e-7c379b7e7123@linaro.org>
@ 2017-04-06 16:11       ` Adhemerval Zanella
  2017-04-18 21:21         ` Joseph Myers
  0 siblings, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2017-04-06 16:11 UTC (permalink / raw)
  To: GNU C Library



On 27/03/2017 12:34, Adhemerval Zanella wrote:
> 
> 
> On 16/03/2017 14:00, Adhemerval Zanella wrote:
>>
>>
>> On 16/03/2017 10:58, Andreas Schwab wrote:
>>> On Mär 16 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>>>
>>>> diff --git a/sysdeps/s390/s390-32/symbol-hacks.h b/sysdeps/s390/s390-32/symbol-hacks.h
>>>> new file mode 100644
>>>> index 0000000..82fb0f6
>>>> --- /dev/null
>>>> +++ b/sysdeps/s390/s390-32/symbol-hacks.h
>>>> @@ -0,0 +1,19 @@
>>>> +/* Hacks needed for symbol manipulation.  s390 version.
>>>> +   Copyright (C) 2017 Free Software Foundation, Inc.
>>>> +   This file is part of the GNU C Library.
>>>> +
>>>> +   The GNU C Library is free software; you can redistribute it and/or
>>>> +   modify it under the terms of the GNU Lesser General Public
>>>> +   License as published by the Free Software Foundation; either
>>>> +   version 2.1 of the License, or (at your option) any later version.
>>>> +
>>>> +   The GNU C Library is distributed in the hope that it will be useful,
>>>> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>>>> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>>> +   Lesser General Public License for more details.
>>>> +
>>>> +   You should have received a copy of the GNU Lesser General Public
>>>> +   License along with the GNU C Library; if not, see
>>>> +   <http://www.gnu.org/licenses/>.  */
>>>> +
>>>> +#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
>>>
>>> No include_next?
>>>
>>> Andreas.
>>>
>>
>> Right, it is missing.  I will add it.
>>
> 
> Any more impending remarks about this patch?
> 

If no one opposes I will commit both patches.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-04-06 16:11       ` Adhemerval Zanella
@ 2017-04-18 21:21         ` Joseph Myers
  2017-04-18 22:29           ` Adhemerval Zanella
  2017-04-19 21:01           ` Adhemerval Zanella
  0 siblings, 2 replies; 13+ messages in thread
From: Joseph Myers @ 2017-04-18 21:21 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

I think these changes caused elf/check-execstack to fail for 
sparcv9-linux-gnu.

https://sourceware.org/ml/libc-testresults/2017-q2/msg00015.html (before 
the change, passes)

https://sourceware.org/ml/libc-testresults/2017-q2/msg00018.html (after 
the change, shows the regression, no other changes in glibc).

/scratch/jmyers/glibc-bot/build/glibcs/sparcv9-linux-gnu/glibc/elf/ld.so.phdr: *** executable stack signaled

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-04-18 21:21         ` Joseph Myers
@ 2017-04-18 22:29           ` Adhemerval Zanella
  2017-04-19 21:01           ` Adhemerval Zanella
  1 sibling, 0 replies; 13+ messages in thread
From: Adhemerval Zanella @ 2017-04-18 22:29 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library



On 18/04/2017 18:21, Joseph Myers wrote:
> I think these changes caused elf/check-execstack to fail for 
> sparcv9-linux-gnu.
> 
> https://sourceware.org/ml/libc-testresults/2017-q2/msg00015.html (before 
> the change, passes)
> 
> https://sourceware.org/ml/libc-testresults/2017-q2/msg00018.html (after 
> the change, shows the regression, no other changes in glibc).
> 
> /scratch/jmyers/glibc-bot/build/glibcs/sparcv9-linux-gnu/glibc/elf/ld.so.phdr: *** executable stack signaled
> 

I will check this out.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-04-18 21:21         ` Joseph Myers
  2017-04-18 22:29           ` Adhemerval Zanella
@ 2017-04-19 21:01           ` Adhemerval Zanella
  2017-05-10 13:24             ` Joseph Myers
  1 sibling, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2017-04-19 21:01 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library



On 18/04/2017 18:21, Joseph Myers wrote:
> I think these changes caused elf/check-execstack to fail for 
> sparcv9-linux-gnu.
> 
> https://sourceware.org/ml/libc-testresults/2017-q2/msg00015.html (before 
> the change, passes)
> 
> https://sourceware.org/ml/libc-testresults/2017-q2/msg00018.html (after 
> the change, shows the regression, no other changes in glibc).
> 
> /scratch/jmyers/glibc-bot/build/glibcs/sparcv9-linux-gnu/glibc/elf/ld.so.phdr: *** executable stack signaled
> 

I think the problem is with generated sparc toolchain from build-many-glibcs.py
the minimum supported sparc32 version is pre-v9 and it requires a software
implementation of '.udiv'.  Since now we are using libgcc.a one instead, it
must have the '.note.GNU-stack' so linker can properly set the stack non
executable.

From a build using a toolchain from build-many-glibcs.py:

elf/librtld.os.map

[...]
/opt/cross/sparc64-linux-gnu/bin/../lib/gcc/sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_divsi3.o)
                              /opt/cross/sparc64-linux-gnu/bin/../lib/gcc/sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_udivdi3.o) (.udiv)
/opt/cross/sparc64-linux-gnu/bin/../lib/gcc/sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_clz.o)
                              /opt/cross/sparc64-linux-gnu/bin/../lib/gcc/sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_udivdi3.o) (__clz_tab)
[...]

And dumping _udivdi3.o section headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 0002b0 00  AX  0   0  4
  [ 2] .data             PROGBITS        00000000 0002e4 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          00000000 0002e4 000000 00  WA  0   0  1
  [ 4] .debug_line       PROGBITS        00000000 0002e4 00010d 00      0   0  1
  [ 5] .rela.debug_line  RELA            00000000 0007c0 00000c 0c   I 12   4  4
  [ 6] .debug_info       PROGBITS        00000000 0003f1 0000ab 00      0   0  1
  [ 7] .rela.debug_info  RELA            00000000 0007cc 000030 0c   I 12   6  4
  [ 8] .debug_abbrev     PROGBITS        00000000 00049c 000014 00      0   0  1
  [ 9] .debug_aranges    PROGBITS        00000000 0004b0 000020 00      0   0  8
  [10] .rela.debug_arang RELA            00000000 0007fc 000018 0c   I 12   9  4
  [11] .shstrtab         STRTAB          00000000 000814 000070 00      0   0  1
  [12] .symtab           SYMTAB          00000000 0004d0 000220 10     13  32  4
  [13] .strtab           STRTAB          00000000 0006f0 0000cf 00      0   0  1

I am not seeing this on a native gcc build which I configured with:

' --with-arch-directory=sparc64 --enable-multiarch --enable-targets=all 
  --with-cpu-32=ultrasparc --with-long-double-128 --enable-multilib'

Both libgcc's __udivdi3 and __umoddi3 do not pull .udiv since for this libgcc build
both are using hardware instructions:

elf/librtld.os.map

/home/azanella/gcc/install/lib/gcc/sparc64-linux-gnu/6.3.1/32/libgcc.a(_udivdi3.o)
                              /home/azanella/glibc/glibc-git-build-sparcv9/elf/dl-allobjs.os (__udivdi3)
/home/azanella/gcc/install/lib/gcc/sparc64-linux-gnu/6.3.1/32/libgcc.a(_umoddi3.o)
                              /home/azanella/glibc/glibc-git-build-sparcv9/elf/dl-allobjs.os (__umoddi3)

Now to actually fix it I can think of two possible solutions:

  1. Add divdi3 build on sparc32 as before the patch.
  2. Enforce -Wl,-noexecstack on ld.so build.

I would prefer 2. since we already expect loader to have a non-executable stack
and gentoo wiki [1] all current architectures with supported gcc/binutils version
should support the linker option. 

[1] https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-04-19 21:01           ` Adhemerval Zanella
@ 2017-05-10 13:24             ` Joseph Myers
  2017-05-10 20:24               ` Adhemerval Zanella
  0 siblings, 1 reply; 13+ messages in thread
From: Joseph Myers @ 2017-05-10 13:24 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Wed, 19 Apr 2017, Adhemerval Zanella wrote:

> Now to actually fix it I can think of two possible solutions:
> 
>   1. Add divdi3 build on sparc32 as before the patch.
>   2. Enforce -Wl,-noexecstack on ld.so build.

3. Add .note.GNU-stack section in libgcc/config/sparc/lb1spc.S (possibly 
conditioned on defined(__ELF__) && defined(__linux__), as in other 
architecture-specific .S files).  That seems to me to be the right 
approach, and would fix it for other software using these libgcc functions 
as well.  And as a very small safe patch it should be suitable for 
backporting onto active GCC release branches.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] Build divdi3 only for architecture that required it
  2017-05-10 13:24             ` Joseph Myers
@ 2017-05-10 20:24               ` Adhemerval Zanella
  0 siblings, 0 replies; 13+ messages in thread
From: Adhemerval Zanella @ 2017-05-10 20:24 UTC (permalink / raw)
  To: Joseph Myers; +Cc: GNU C Library



On 10/05/2017 10:23, Joseph Myers wrote:
> On Wed, 19 Apr 2017, Adhemerval Zanella wrote:
> 
>> Now to actually fix it I can think of two possible solutions:
>>
>>   1. Add divdi3 build on sparc32 as before the patch.
>>   2. Enforce -Wl,-noexecstack on ld.so build.
> 
> 3. Add .note.GNU-stack section in libgcc/config/sparc/lb1spc.S (possibly 
> conditioned on defined(__ELF__) && defined(__linux__), as in other 
> architecture-specific .S files).  That seems to me to be the right 
> approach, and would fix it for other software using these libgcc functions 
> as well.  And as a very small safe patch it should be suitable for 
> backporting onto active GCC release branches.
> 

Done [1].

[1] https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00824.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-05-10 20:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 13:43 [PATCH 1/2] Build divdi3 only for architecture that required it Adhemerval Zanella
2017-03-16 13:43 ` [PATCH 2/2] sparc: Fix .udiv plt on libc Adhemerval Zanella
2017-03-16 14:45   ` Florian Weimer
2017-03-16 16:59     ` Adhemerval Zanella
2017-03-27 15:33       ` Adhemerval Zanella
2017-03-16 13:58 ` [PATCH 1/2] Build divdi3 only for architecture that required it Andreas Schwab
2017-03-16 17:00   ` Adhemerval Zanella
     [not found]     ` <af83ffde-83d3-d7d1-d45e-7c379b7e7123@linaro.org>
2017-04-06 16:11       ` Adhemerval Zanella
2017-04-18 21:21         ` Joseph Myers
2017-04-18 22:29           ` Adhemerval Zanella
2017-04-19 21:01           ` Adhemerval Zanella
2017-05-10 13:24             ` Joseph Myers
2017-05-10 20:24               ` Adhemerval Zanella

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).