This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

BFD and global variables


Is there anyway to change the .data section of a file
using BFD?

I have the following code that does not work:
file_buffer is an array filled with fread() of the file that the BFD corresponds to.


-----------------------------------------------------------------------------------------------
#define ELF_BASE_VMA 0x8048000
unsigned int *data_section_ptr;
int offset;

offset = symbol_table[i]->section->vma + symbol_table[i]->value
                        - ELF_BASE_VMA;
(unsigned int)data_section_ptr = (unsigned int)file_buffer + offset;
*data_section_ptr = some_value;
-----------------------------------------------------------------------------------------------

BUT, this code does work for changing the .text section:
it changes the value that a pushl instruction will use.
-----------------------------------------------------------------------------------------------
unsigned int *pushl_id_ptr;
int offset;

offset = symbol_table[i]->section->vma + symbol_table[i]->value
- ELF_BASE_VMA;
(unsigned int)pushl_id_ptr = (unsigned int)file_buffer + offset + 4;
*pushl_id_ptr = rand(); -----------------------------------------------------------------------------------------------


After I have updated file_buffer, I write it off to another file with fwrite().

For some reason, my pointer into the file array is pointing at
a bunch of 0's.  If I do objdump -s and look at the .data section,
there is plenty of (non-zero) data there.



Regards,
Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]