There are really two questions that revolve around using --add-section. Simple in name. Based on my reading, I was not able to figure out how to perform the -add-section.
To use an additional section, I need to pass the name of the section. If I use the name of an existing section, the program says "cannot add the section .data": file in the wrong format ". Maybe I just need to pass another parameter. If I use a new section name, which I would prefer to do, I warned that the "highlighted section" .blob is "not in the segment".
Now I got my function to work as I need, aside from the warning "not in the segment." I would like to find out if there is a legal way to put this blob in an executable. I would link it, but itβs not so simple, because the data that I add is generated from the contents of the executable itself.
The second question is really what I care about. Is there a way to do the following, given that blob cannot be computed until the link is complete.
- Link to ELF file
- Generate blob from ELF file and other data
Add blob to ELF file so that it loads at runtime to the desired location in memory
objcopy --add-section .blob=blob.o \ --set-section-flags .blob=alloc,contents,load,readonly \ --change-section-address .blob=ADDRESS \ program.elf program.blobbed.elf
I would be happy to add a section and / or segment to the ELF file as part of the link and paste this blob there. I am not sure how to do this.
It occurred to me that I could accomplish this feat with a second link, but objcopy would be cleaner.
- Link to ELF file
- Generate blob from ELF file and other data
- Rename the ELF file, including the new blob.o
UPDATE: This last strategy can be workable until the relink changes something in the part of the program that was created by the first link. This does not apply to the first attempts, but you can get around this. Therefore, the desire to use -add-section to add to this blob instead of going through the second link.
source share