This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Question wrt libelf
- From: Marcus Clyne <maccaday at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 28 Aug 2009 18:05:35 +0300
- Subject: Question wrt libelf
Hi,
I have a question about libelf / gelf. I know that it's not part of
binutils, but I couldn't find a mailing list for libelf itself and since
it's closely related, I hope people don't mind me posting here.
I'm trying to update the information of a global symbol. I've got as
far as reading the symbol names, but am unsure how to update the
information in the symbol.
My code so far is roughly (I've left out the error checks, and when no
entries match here):
Elf *e;
Elf_Scn *scn;
GElf_Shdr shdr;
GElf_Sym sym;
Elf_Data *data;
uint64_t count, i;
char *name;
elf_version (EV_CURRENT);
e = elf_begin (fd, ELF_C_RDWR, NULL);
scn = NULL;
while ((scn = elf_nextscn (e, scn)) != NULL) {
gelf_getshdr (scn, &shdr);
// break on symbol table
if (shdr.sh_type == SHT_SYMTAB)
break;
}
}
data = elf_getdata (scn, NULL);
count = shdr.sh_size / shdr.sh_entsize;
// find the symbol in the table
for (i = 0; i < count; i++) {
gelf_getsym (data, i, &sym);
name = elf_strptr (e, shdr.sh_link, sym.st_name);
if (strcmp (name, "my_symbol") == 0)
break;
}
Here's where I'm stuck. I'd like to be able to access and change the
value of the symbol, but I'm not sure how to do so and I've not found a
manual that describes it yet.
Can anyone point me in the right direction?
Thanks,
Marcus.