[Cbe-oss-dev] embedspu and execstack

Kazunori Asayama asayama at sm.sony.co.jp
Fri Oct 3 01:03:59 EST 2008


I'm now testing Fedora 10 (rawhide) as Cell programming environment:

Gcc and binutils in Fedora 10 are:

  * gcc version 4.3.2 20080917 (Red Hat 4.3.2-4)

  * binutils version 2.18.50.0.9 (ppc-redhat-linux)
           using BFD version version 2.18.50.0.9-5.fc10 20080822

Then, I have a trouble as below when running a test program which uses
shared library with embedded SPU ELF.

When I ran that program on Fedora 10, I was complained:

    cannot enable executable stack as shared object requires: Permission denied

I looked into this problem and found that the 'embedspu' script caused
that. The embedspu internally generate an assembly source code and
pass it to the assembler. The object generated by the assembler has no
".note.GNU-stack" section:

---
# embedspu -fpic spu_prog spu_prog.elf spu_prog_embed.o
# gcc -shared spu_prog_embed.o -o libtest.so
# execstack -q libtest.so
X libtest.so
# readelf -S spu_prog_embed.o
There are 12 section headers, starting at offset 0xd67c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            00000000 000034 000024 00   A  0   0  4
  [ 2] .text             PROGBITS        00000000 000058 000000 00  AX  0   0  1
  [ 3] .rodata.speelf    PROGBITS        00000000 000080 00d580 00   A  0   0 128
  [ 4] .data             PROGBITS        00000000 00d600 000000 00  WA  0   0  1
  [ 5] .data.spetoe      PROGBITS        00000000 00d600 000000 00  WA  0   0 128
  [ 6] .data.spehandle   PROGBITS        00000000 00d600 00000c 00  WA  0   0  4
  [ 7] .rela.data.spehan RELA            00000000 00d85c 000018 0c     10   6  4
  [ 8] .bss              NOBITS          00000000 00d60c 000000 00  WA  0   0  1
  [ 9] .shstrtab         STRTAB          00000000 00d60c 000070 00      0   0  1
  [10] .symtab           SYMTAB          00000000 00d874 000090 10     11   8  4
  [11] .strtab           STRTAB          00000000 00d904 00000a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

---

so the linker assumes the object may require executable stack. As a
result of that, the shared object with embedded SPU ELF is marked as
"requires executable stack".

I suppose this problem is not specific to Fedora 10, but generic.

This problem can be fixed by passing '-Wa,-noexecstack' option to the
assembler via the 'embedspu' script:

---
# embedspu -fpic -Wa,-noexecstack spu_prog spu_prog.elf spu_prog_embed.o
# gcc -shared spu_prog_embed.o -o libtest.so
# execstack -q libtest.so
- libtest.so
# readelf -S spu_prog_embed.o
There are 13 section headers, starting at offset 0xd68c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            00000000 000034 000024 00   A  0   0  4
  [ 2] .text             PROGBITS        00000000 000058 000000 00  AX  0   0  1
  [ 3] .rodata.speelf    PROGBITS        00000000 000080 00d580 00   A  0   0 128
  [ 4] .data             PROGBITS        00000000 00d600 000000 00  WA  0   0  1
  [ 5] .data.spetoe      PROGBITS        00000000 00d600 000000 00  WA  0   0 128
  [ 6] .data.spehandle   PROGBITS        00000000 00d600 00000c 00  WA  0   0  4
  [ 7] .rela.data.spehan RELA            00000000 00d894 000018 0c     11   6  4
  [ 8] .bss              NOBITS          00000000 00d60c 000000 00  WA  0   0  1
  [ 9] .note.GNU-stack   PROGBITS        00000000 00d60c 000000 00      0   0  1
  [10] .shstrtab         STRTAB          00000000 00d60c 000080 00      0   0  1
  [11] .symtab           SYMTAB          00000000 00d8ac 0000a0 10     12   9  4
  [12] .strtab           STRTAB          00000000 00d94c 00000a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
---

Of course, I can fix this problem by always adding '-Wa,-noexecstack'
option to embedspu, however, I feel it's reasonable the embedspu
script adds that option implicitly.

Any comments?

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list