[Ltrace-devel] [PATCH 3/6] Fix formatting specifiers for printing GElf_Addr
Zachary T Welch
zwelch at codesourcery.com
Tue Dec 7 07:21:00 UTC 2010
The use of GElf_Addr types was causing warnings when printed with %lx
format specifiers. This patch fixes the problem by using the portable
<inttypes.h> header and PRIx64 macro.
In a few places, added missing alternate form specifier ('#') to ensure
0x prefix is printed for the addresses in question.
Signed-off-by: Zachary T Welch <zwelch at codesourcery.com>
---
ltrace-elf.c | 16 +++++++++-------
sysdeps/linux-gnu/proc.c | 5 ++++-
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/ltrace-elf.c b/ltrace-elf.c
index 29e9c9c..81185fe 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -5,6 +5,7 @@
#include <error.h>
#include <fcntl.h>
#include <gelf.h>
+#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -106,7 +107,7 @@ static GElf_Addr get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot,
&& !get_section_covering(lte, ppcgot, &ppcgot_sec, &ppcgot_shdr))
// xxx should be the log out
fprintf(stderr,
- "DT_PPC_GOT=%#lx, but no such section found.\n",
+ "DT_PPC_GOT=%#" PRIx64 ", but no such section found.\n",
ppcgot);
if (ppcgot_sec != NULL) {
@@ -119,7 +120,7 @@ static GElf_Addr get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot,
size_t offset = ppcgot - ppcgot_shdr.sh_addr;
GElf_Addr glink_vma = read32be(data, offset + 4);
if (glink_vma != 0) {
- debug(1, "PPC GOT glink_vma address: %#lx",
+ debug(1, "PPC GOT glink_vma address: %#" PRIx64,
glink_vma);
return glink_vma;
}
@@ -128,7 +129,7 @@ static GElf_Addr get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot,
if (plt_data != NULL) {
GElf_Addr glink_vma = read32be(plt_data, 0);
- debug(1, ".plt glink_vma address: %#lx", glink_vma);
+ debug(1, ".plt glink_vma address: %#" PRIx64, glink_vma);
return glink_vma;
}
@@ -304,7 +305,7 @@ do_init_elf(struct ltelf *lte, const char *filename) {
relplt_size = dyn.d_un.d_val;
else if (dyn.d_tag == DT_PPC_GOT) {
ppcgot = dyn.d_un.d_val;
- debug(1, "ppcgot %#lx", ppcgot);
+ debug(1, "ppcgot %#" PRIx64, ppcgot);
}
}
} else if (shdr.sh_type == SHT_HASH) {
@@ -419,7 +420,7 @@ do_init_elf(struct ltelf *lte, const char *filename) {
size_t count = relplt_size / 12; // size of RELA entry
lte->plt_stub_vma = glink_vma
- (GElf_Addr)count * PPC_PLT_STUB_SIZE;
- debug(1, "stub_vma is %#lx", lte->plt_stub_vma);
+ debug(1, "stub_vma is %#" PRIx64, lte->plt_stub_vma);
}
for (i = 1; i < lte->ehdr.e_shnum; ++i) {
@@ -511,7 +512,7 @@ symbol_matches(struct ltelf *lte, size_t lte_i, GElf_Sym *sym,
error(EXIT_FAILURE, 0, "Couldn't get symbol from .dynsym");
else {
tmp->st_value += lte[lte_i].base_addr;
- debug(2, "symbol found: %s, %zd, %lx",
+ debug(2, "symbol found: %s, %zd, %#" PRIx64,
name, lte_i, tmp->st_value);
}
return tmp->st_value != 0
@@ -770,7 +771,8 @@ read_elf(Process *proc) {
GElf_Sym sym;
GElf_Addr addr;
if (in_load_libraries(xptr->name, lte, library_num+1, &sym)) {
- debug(2, "found symbol %s @ %lx, adding it.", xptr->name, sym.st_value);
+ debug(2, "found symbol %s @ %#" PRIx64 ", adding it.",
+ xptr->name, sym.st_value);
addr = sym.st_value;
if (ELF32_ST_TYPE (sym.st_info) == STT_FUNC) {
add_library_symbol(addr, xptr->name, lib_tail, LS_TOPLT_NONE, 0);
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index d11b61b..642cb32 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -2,6 +2,7 @@
#include "common.h"
#include <sys/types.h>
+#include <inttypes.h>
#include <link.h>
#include <stdio.h>
#include <string.h>
@@ -178,7 +179,9 @@ linkmap_add_cb(void *data) { //const char *lib_name, ElfW(Addr) addr) {
GElf_Addr addr;
if (in_load_libraries(xptr->name, <e, 1, &sym)) {
- debug(2, "found symbol %s @ %lx, adding it.", xptr->name, sym.st_value);
+ debug(2, "found symbol %s @ %#" PRIx64
+ ", adding it.",
+ xptr->name, sym.st_value);
addr = sym.st_value;
add_library_symbol(addr, xptr->name, &library_symbols, LS_TOPLT_NONE, 0);
xptr->found = 1;
--
1.7.2.2
More information about the Ltrace-devel
mailing list