Some ELF-related variables differ depending on the native host, so
this patch uses conditional compilation tricks to ensure everything
works out on both 32- and 64-bit hosts.

Signed-off-by: Zachary T Welch <[email protected]>
---
 ltrace-elf.c             |    5 +++--
 ltrace-elf.h             |    9 +++++++++
 sysdeps/linux-gnu/proc.c |    6 ++++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/ltrace-elf.c b/ltrace-elf.c
index e3ef5c3..68cc67c 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -363,8 +363,9 @@ do_init_elf(struct ltelf *lte, const char *filename) {
                        if (shdr.sh_entsize != 0
                            && shdr.sh_entsize != 4) {
                                error(EXIT_FAILURE, 0,
-                                     ".gnu.hash sh_entsize in \"%s\" should be 
4, but is %llu",
-                                     filename, shdr.sh_entsize);
+                                     ".gnu.hash sh_entsize in \"%s\" "
+                                       "should be 4, but is %#" PRIx64,
+                                       filename, shdr.sh_entsize);
                        }
 
                        data = loaddata(scn, &shdr);
diff --git a/ltrace-elf.h b/ltrace-elf.h
index 37f2a18..a29fe2c 100644
--- a/ltrace-elf.h
+++ b/ltrace-elf.h
@@ -51,4 +51,13 @@ extern GElf_Addr arch_plt_sym_val(struct ltelf *, size_t, 
GElf_Rela *);
 #ifndef SHT_GNU_HASH
 #define SHT_GNU_HASH   0x6ffffff6      /* GNU-style hash table. */
 #endif
+
+#if __WORDSIZE == 32
+#define PRI_ELF_ADDR           PRIx32
+#define GELF_ADDR_CAST(x)      (void *)(uint32_t)(x)
+#else
+#define PRI_ELF_ADDR           PRIx64
+#define GELF_ADDR_CAST(x)      (void *)(x)
+#endif
+
 #endif
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index 3c17e1f..4e7733d 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -112,7 +112,9 @@ crawl_linkmap(Process *proc, struct r_debug *dbg, void 
(*callback)(void *), stru
                }
 
                if (callback) {
-                       debug(2, "Dispatching callback for: %s, Loaded at 
0x%x\n", lib_name, rlm.l_addr);
+                       debug(2, "Dispatching callback for: %s, "
+                                       "Loaded at 0x%" PRI_ELF_ADDR "\n",
+                                       lib_name, rlm.l_addr);
                        data->addr = rlm.l_addr;
                        data->lib_name = lib_name;
                        callback(data);
@@ -252,7 +254,7 @@ hook_libdl_cb(void *data) {
 
 int
 linkmap_init(Process *proc, struct ltelf *lte) {
-       void *dbg_addr = NULL, *dyn_addr = (void *)(unsigned)lte->dyn_addr;
+       void *dbg_addr = NULL, *dyn_addr = GELF_ADDR_CAST(lte->dyn_addr);
        struct r_debug *rdbg = NULL;
        struct cb_data data;
 
-- 
1.7.2.2


_______________________________________________
Ltrace-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/ltrace-devel

Reply via email to