1

I am using objcopy to convert elf to hex. When I disassemble the elf in IDA Pro, all the sections are present, but they are missing from my hex and it seems the elf headers:

C:\TricoreGCC>tricore-readelf -l test1.elf

Elf file type is EXEC (Executable file)
Entry point 0x80132000
There are 3 program headers, starting at offset 52

Program Headers:
Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
LOAD           0x000000 0x80130000 0x80130000 0x023e8 0x023e8 R E 0x4000
LOAD           0x003000 0x801cb000 0x801cb000 0x01478 0x01478 RW  0x4000
LOAD           0x005500 0xd0015500 0xd0015500 0x00000 0x00008 RW  0x4000

Section to Segment mapping:
Segment Sections...
00     .text .rodata
01     .data
02     .bss

In an assembler file I have this:

.section .jfuel , "x"
j translatefuel

In a linker script file I have this:

SECTIONS
{
. = 0x800B5964;
.jfuel : { *(.jfuel) }
. = 0x80132000;
.text : { *(.text) }
.rodata : { *(.rodata) }
. = 0x801CB000;
.data : { *(.data) }
. = 0xD0015500;
.bss : { *(.bss) }
}

The elf file does contain symbols from this section though:

Symbol table '.symtab' contains 85 entries:
Num:    Value  Size Type    Bind   Vis      Ndx Name
 0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
 1: 800b5964     0 SECTION LOCAL  DEFAULT    1...

and later there is my .text section:

 5: 80132000     0 SECTION LOCAL  DEFAULT    5...

Somehow I am not defining the section properly in the linker script file. Because it doesn't have a traditional name like .text I'm missing something that is stopping it getting into the sections to "load" into the elf and hence the hex, although IDA Pro loading the elf is showing the sections correctly placed, and their contents.

Posting in RE because I'm patching binaries with a combination of C and asm.

Thanks!

4
  • what exactly do you mean by "missing from my hex"?
    – Igor Skochinsky
    Apr 5, 2017 at 8:04
  • @IgorSkochinsky There are four bytes of code in the .jfuel section that appear in IDA Pro when I load the elf, but they do not show in the hex file loaded into Hex Workshop. tricore-objcopy --set-start=0x80000000 -O ihex test1.elf test1.hex is the conversion I am using from elf to hex.
    – John Banks
    Apr 5, 2017 at 9:54
  • 1
    please post full dump of your elf headers (the one you posted doesn't mention .jfuel so seems to be something else)
    – Igor Skochinsky
    Apr 5, 2017 at 10:04
  • @IgorSkochinsky That was the clue I needed, thanks! .text has AX (alloc, execute) whereas .jfuel only had X. I changed the assembler file to show .section .jfuel , "ax" j translatefuel where ax replaced x and now the hex file contains everything.
    – John Banks
    Apr 5, 2017 at 12:10

1 Answer 1

0

Answer in this case after hint from @Igor Skochinsky is:

Change:

.section .jfuel , "x"
j translatefuel

To:

.section .jfuel , "ax"
j translatefuel

.text has AX (alloc, execute) by default whereas .jfuel only had X because that was all I added originally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.