summaryrefslogtreecommitdiff
path: root/rld-elf.cpp
diff options
context:
space:
mode:
authorPeng Fan <van.freenix@gmail.com>2013-08-29 19:41:23 +0800
committerPeng Fan <van.freenix@gmail.com>2013-08-29 19:41:23 +0800
commit1d2c9b7f8001c21c472c7da8a18739c3d48a5718 (patch)
tree8a6b7d59a6d0f6713530fdc18a0b25b4ce41f99c /rld-elf.cpp
parent7f982b32bd276d08c5273353073cc6958aaaecac (diff)
Fix archive writer
1. align to even address 2. Fix the use of GElf_Ehdr and Elf32_Ehdr 3. Fix the header related
Diffstat (limited to 'rld-elf.cpp')
-rw-r--r--rld-elf.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/rld-elf.cpp b/rld-elf.cpp
index 19aa1ab..8b2ac5e 100644
--- a/rld-elf.cpp
+++ b/rld-elf.cpp
@@ -1006,14 +1006,30 @@ namespace rld
if (ehdr == 0)
error ("gelf_newehdr");
- if (::gelf_getehdr (elf_, ehdr) == 0)
+ if (class_ == ELFCLASS32)
+ {
+ if((ehdr = (elf_ehdr*) ::elf32_getehdr (elf_)) == 0)
+ error ("elf32_getehdr");
+ }
+ else if (::gelf_getehdr (elf_, ehdr) == 0)
error ("gelf_getehdr");
- ehdr->e_type = type;
- ehdr->e_machine = machinetype;
- ehdr->e_flags = 0;
- ehdr->e_ident[EI_DATA] = datatype;
- ehdr->e_version = EV_CURRENT;
+ if (class_ == ELFCLASS32)
+ {
+ ((elf32_ehdr*)ehdr)->e_type = type;
+ ((elf32_ehdr*)ehdr)->e_machine = machinetype;
+ ((elf32_ehdr*)ehdr)->e_flags = 0;
+ ((elf32_ehdr*)ehdr)->e_ident[EI_DATA] = datatype;
+ ((elf32_ehdr*)ehdr)->e_version = EV_CURRENT;
+ }
+ else
+ {
+ ehdr->e_type = type;
+ ehdr->e_machine = machinetype;
+ ehdr->e_flags = 0;
+ ehdr->e_ident[EI_DATA] = datatype;
+ ehdr->e_version = EV_CURRENT;
+ }
::elf_flagphdr (elf_, ELF_C_SET , ELF_F_DIRTY);
}