This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] sparc: Set noexecstack on mulsi3, divsi3, and modsi3


A recent GLIBC fix for sparc [1] made some configuration to show
an executable stack on ld.so (shown on elf/check-execstack testcase
failure).

It is because with generated sparc toolchain from build-many-glibcs.py
(a GLIBC script to produce cross-compiling toolchains) 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

[...]
.../sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_divsi3.o)
                              .../sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_udivdi3.o) (.udiv)
.../sparc64-glibc-linux-gnu/6.2.1/32/libgcc.a(_clz.o)
                              .../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)

This patch adds them missing noexectack on sparc assembly implementation.  I saw
no regression on gcc testsuite and it fixes the regression on GLIBC side.

libgcc/

	* config/sparc/lb1spc.S [__ELF__ && __linux__]: Emit .note.GNU-stack
	section for a non-executable stack.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=bdc543e338281da051b3dc06eae96c330a485ce6
---
 libgcc/ChangeLog             | 5 +++++
 libgcc/config/sparc/lb1spc.S | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/libgcc/config/sparc/lb1spc.S b/libgcc/config/sparc/lb1spc.S
index b60bd57..e693864 100644
--- a/libgcc/config/sparc/lb1spc.S
+++ b/libgcc/config/sparc/lb1spc.S
@@ -5,6 +5,12 @@
    slightly edited to match the desired calling convention, and also to
    optimize them for our purposes.  */
 
+/* An executable stack is *not* required for these functions.  */
+#if defined(__ELF__) && defined(__linux__)
+.section .note.GNU-stack,"",%progbits
+.previous
+#endif
+
 #ifdef L_mulsi3
 .text
 	.align 4
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]