Go Back   Exetools > General > General Discussion


Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 06-13-2021, 13:43
dion dion is offline
game tech
Join Date: Jan 2002
Posts: 165
Rept. Given: 13
Rept. Rcvd 2 Times in 2 Posts
Thanks Given: 5
Thanks Rcvd at 4 Times in 4 Posts
dion Reputation: 2
Need help figuring out why my powerpc elf file causing seg fault


basically, i am trying to embed a vxworks image into an elf binary (a simple hello world c application), just to see if it is possible. if it is possible, i plan to use call cast on the c code to verify certain functions inside vxworks image. but after weeks, i find no way to make this elf run without seg fault (using qemu-ppc). thus, i need help.

so, i used debian, and the commands were like these :
powerpc-linux-gnu-objcopy -I binary -O elf32-powerpc -B powerpc vxs vxw.o
powerpc-linux-gnu-objcopy --set-section-flags .data=alloc,load,code vxw.o
powerpc-linux-gnu-objcopy --rename-section .data=.vxworks vxw.o
powerpc-linux-gnu-gcc -Wall -Werror -g hello.c -o myprog -T myscript vxw.o -static
vxs is prepared vxworks image. but it can be any binary blob. hello.c :
#include <stdio.h>

extern unsigned char _binary_vxs_start;
extern unsigned char _binary_vxs_end;

int main()
	printf("Hello World!\n");
	unsigned char *pblob = &_binary_vxs_start;
    	int i = 0;
	while (i < 100)
	printf("%x: %02X\n", pblob - &_binary_vxs_start, *pblob);

	return 0;
the linker script is default linker script modified. i got the default by :
powerpc-linux-gnu-ld --verbose
i listed here the modifications :
  /* Read-only sections, merged into text segment: */
  /* PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x10000000)); . = SEGMENT_START("text-segment", 0x10000000) + SIZEOF_HEADERS; */
  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x000FFF4C)); 
  . = SEGMENT_START("text-segment", 0x000FFF4C) + SIZEOF_HEADERS; 

  .vxworks	  : { *(.vxworks) } 
  .interp         : { *(.interp) }
the elf file constructed successfully without any warning. but when run it with "qemu-ppc myprog", it seg fault. this seg fault seems only happen when i set the segment start (in linker script) to that very value. if i set them to other value, they seems to run normally. so, is there anyway to track why seg fault happen?

tried to compare both working elf and notworking elf with readelf, the not working one, doesn't have __ehdr_start. i tried to add that symbol in the linker script :
__ehdr_start = 0x000FFF4C;
but not worked (still seg fault). it compiled the symbol as global and abs. i can not find anything from google concern this.

any help appreciated.
thanks in advance.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

All times are GMT +8. The time now is 13:37.

Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2021 )