2017-07-22 24 views
4

私はRaspbian GNU/Linux 8(Jessie)OSのRaspberry Pi 3を持っています。スタックセグメントがRaspberry Piで実行可能なのはなぜですか?

私はこの簡単なプログラムを書いています。私はgcc -o hello hello.cでそれを集めました。

Program Headers: 
    Type   Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align 
    EXIDX   0x0004cc 0x000104cc 0x000104cc 0x00008 0x00008 R 0x4 
    PHDR   0x000034 0x00010034 0x00010034 0x00120 0x00120 R E 0x4 
    INTERP   0x000154 0x00010154 0x00010154 0x00019 0x00019 R 0x1 
     [Requesting program interpreter: /lib/ld-linux-armhf.so.3] 
    LOAD   0x000000 0x00010000 0x00010000 0x004d8 0x004d8 R E 0x10000 
    LOAD   0x000f0c 0x00020f0c 0x00020f0c 0x0011c 0x00120 RW 0x10000 
    DYNAMIC  0x000f18 0x00020f18 0x00020f18 0x000e8 0x000e8 RW 0x4 
    NOTE   0x000170 0x00010170 0x00010170 0x00044 0x00044 R 0x4 
    GNU_STACK  0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10 
    GNU_RELRO  0x000f0c 0x00020f0c 0x00020f0c 0x000f4 0x000f4 R 0x1 

しかし、私はプログラムを実行すると、スタックは実行可能です::readelfが出力のすべてからから

#include <stdio.h> 

void main(){ 
    printf("hello!\n"); 
} 

はOKらしい

0x7efdf000 0x7f000000 0x00000000 rwx [stack] 

私はオプションでもコンパイルしようとし-z noexecstackしかし、何も変わりません。

#if defined(__linux__) && defined(__ELF__) 
.section .note.GNU-stack,"",%progbits 
#endif 

しかし、何も変更:

私はこのコードを持ってlibarmmem.soのバージョンをダウンロードすることもしてみてください。

なぜスタックセグメントはRaspberry Piで実行可能ですか?私は、ファイルarchitecture.Sを編集 、とメイク後に私が受け取っ:

gcc -std=gnu99 -O2 -c -o trampoline.o trampoline.c 
gcc -shared -o libarmmem.so architecture.o memcmp.o memcpymove.o memcpymove-a7.o memset.o trampoline.o 
`architecture' referenced in section `.text' of trampoline.o: defined in discarded section `.note.GNU-stack' of architecture.o 
`architecture' referenced in section `.text' of trampoline.o: defined in discarded section `.note.GNU-stack' of architecture.o 
`architecture' referenced in section `.text' of trampoline.o: defined in discarded section `.note.GNU-stack' of architecture.o 
`architecture' referenced in section `.text' of trampoline.o: defined in discarded section `.note.GNU-stack' of architecture.o 
collect2: error: ld returned 1 exit status 
Makefile:13: recipe for target 'libarmmem.so' failed 
make: *** [libarmmem.so] Error 1 
を、私はより多くの情報を追加

 23110: 
    23110: file=/usr/lib/arm-linux-gnueabihf/libarmmem.so [0]; needed by ./hello [0] 
    23110: file=/usr/lib/arm-linux-gnueabihf/libarmmem.so [0]; generating link map 
    23110: dynamic: 0x76f273fc base: 0x76f13000 size: 0x00014524 
    23110:  entry: 0x76f13568 phdr: 0x76f13034 phnum:   6 
    23110: 
    23110: 
    23110: file=libc.so.6 [0]; needed by ./hello [0] 
    23110: file=libc.so.6 [0]; generating link map 
    23110: dynamic: 0x76f0ef20 base: 0x76dd4000 size: 0x0013e550 
    23110:  entry: 0x76dea840 phdr: 0x76dd4034 phnum:   10 
    23110: 
    23110: 
    23110: calling init: /lib/arm-linux-gnueabihf/libc.so.6 
    23110: 
    23110: 
    23110: calling init: /usr/lib/arm-linux-gnueabihf/libarmmem.so 
    23110: 
    23110: 
    23110: initialize program: ./hello 
    23110: 
    23110: 
    23110: transferring control: ./hello 
    23110: 
hello! 
    23110: 
    23110: calling fini: ./hello [0] 
    23110: 
    23110: 
    23110: calling fini: /usr/lib/arm-linux-gnueabihf/libarmmem.so [0] 
    23110: 

=ファイル./helloコマンドをLD_DEBUGの出力を追加

編集

+0

私の無知を許してください...この結果はどうでしたか: '0x7efdf000 0x7f000000 0x00000000 rwx [stack]'。その部分は「痕跡」ですか? – jww

+0

@jwwいいえ/ proc/'pidof hello'/maps – Livio

+1

プログラムを' LD_DEBUG = files。/ hello'として実行し、出力をあなたの投稿に追加してください。 'LD_PRELOAD'ライブラリがこれを引き起こすという報告がいくつかあります。 –

答えて

2

/usr/lib/arm-linux-gnueabihf/libarmmem.soがこれを引き起こしている可能性があります。 DSOがプリロードされたときのglibcは、保守的、スタックを実行可能になりますので、それは、非実行スタック注釈を欠い

:私は、このソースファイルを見つけました。他のソースファイルには、これを持っている:

/* Prevent the stack from becoming executable */ 
#if defined(__linux__) && defined(__ELF__) 
.section .note.GNU-stack,"",%progbits 
#endif 

だからあなただけの(ファイルの終わり)architecture.Sにこれをコピーして再構築する必要があります。

eu-readelf -l /usr/lib/arm-linux-gnueabihf/libarmmem.soで確認できます。このDSOが本当に原因である場合は、 GNU_STACKプログラムヘッダーはまったく表示されないか、GNU_STACKプログラムヘッダーが表示され、最後から2番目の列にRWEが表示されます。

+0

@Livio、どういうわけか壊れて見えて申し訳ありません。コメントボックスは、コンパイラの出力メッセージを投稿するのには適していません。あなたがしたことと結果が何だったのかを投稿してください。 –

+0

はい残念ですが、(投稿に出力を追加しました – Livio

+1

申し訳ありませんが、私は 'architecture.S'にセクションディレクティブがスタートの近くにないことを忘れました。あなたがファイルの最後に投稿したフラグメントを置く必要があります。あるいは、最初に残しておくと、その後に '.data'ディレクティブを追加します。 –

関連する問題