From: Joseph K. <jk...@us...> - 2011-10-22 06:00:20
|
> ÃÂ $ ./extend-a-section hello > ÃÂ fstat() failed: "Bad address". > ÃÂ Size error: expected=118, elf_update()=6536 > I imagine that I broke something while replacing the TC_* macros > with C code. ÃÂ I apologize for asking such a simple question, but > would you mind taking a look to see if the error is obvious to you. 1) The stat() call at line 46 appears to be failing because argv[2] was not supplied. File "extend-a-section.c": 21 struct stat sb; ... 25 const char *srcfile = argv[1]; 26 const char *reffile = argv[2]; ... 46 if (stat(reffile, &sb) < 0) { 47 printf("fstat() failed: \"%s\".\n", strerror(errno)); 48 } The value of the "sb.st_size" field would be undefined, and this then leads to the failure further down. ... 64 if (fsz1 != sb.st_size) { 65 printf("Size error: expected=%ld, elf_update()=%ld\n", sb.st_size, fsz1); 66 } You could remove these file size checks---they are only relevant for test code. 2) If your code is changing an ELF executable, it would also need to adjust the ELF program header to match the new layout of the file's content---in the ELF(3) API, the contents of the PHDR table are managed by the application, not libelf. Regards, Koshy |