From: Petr Machata Date: Tue, 21 Sep 2010 16:41:13 +0000 (+0200) Subject: dwarflint: Move read_address_size to read_ctx module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb3dfaf9ab0239b71fc367ae806577d4debb6fb9;p=thirdparty%2Felfutils.git dwarflint: Move read_address_size to read_ctx module - and shuffle arguments around so it makes sense --- diff --git a/dwarflint/check_debug_info.cc b/dwarflint/check_debug_info.cc index d99fdadb2..77515328a 100644 --- a/dwarflint/check_debug_info.cc +++ b/dwarflint/check_debug_info.cc @@ -263,7 +263,7 @@ namespace << pri::lacks_relocation ("abbrev table offset") << std::endl; /* Address size. */ - if (!read_address_size (file->addr_64, &ctx, &head.address_size, + if (!read_address_size (&ctx, file->addr_64, &head.address_size, &head.where)) throw check_base::failed (); diff --git a/dwarflint/low.c b/dwarflint/low.c index a5aafb5d4..945af7b44 100644 --- a/dwarflint/low.c +++ b/dwarflint/low.c @@ -196,38 +196,6 @@ check_range_relocations (enum message_category cat, file->sec[end_symbol->st_shndx].name); } -bool -read_address_size (bool elf_64, - struct read_ctx *ctx, - int *address_sizep, - struct where const *where) -{ - uint8_t address_size; - if (!read_ctx_read_ubyte (ctx, &address_size)) - { - wr_error (where, ": can't read address size.\n"); - return false; - } - - if (address_size != 4 && address_size != 8) - { - /* Keep going. Deduce the address size from ELF header, and try - to parse it anyway. */ - wr_error (where, - ": invalid address size: %d (only 4 or 8 allowed).\n", - address_size); - address_size = elf_64 ? 8 : 4; - } - else if ((address_size == 8) != elf_64) - /* Keep going, we may still be able to parse it. */ - wr_error (where, - ": CU reports address size of %d in %d-bit ELF.\n", - address_size, elf_64 ? 64 : 32); - - *address_sizep = address_size; - return true; -} - static void compare_coverage (struct elf_file *file, struct coverage *coverage, struct coverage *other, @@ -389,7 +357,7 @@ check_aranges_structural (struct elf_file *file, /* Address size. */ int address_size; - if (!read_address_size (file->addr_64, &sub_ctx, &address_size, &where)) + if (!read_address_size (&sub_ctx, file->addr_64, &address_size, &where)) { retval = false; goto next; diff --git a/dwarflint/low.h b/dwarflint/low.h index 16a74ac5b..309e13c17 100644 --- a/dwarflint/low.h +++ b/dwarflint/low.h @@ -104,10 +104,6 @@ extern "C" extern bool check_zero_padding (struct read_ctx *ctx, enum message_category category, struct where const *wh); - extern bool read_address_size (bool elf_64, - struct read_ctx *ctx, - int *address_sizep, - struct where const *where); struct section_coverage { diff --git a/dwarflint/readctx.c b/dwarflint/readctx.c index 20bda8d8f..a17bd5a54 100644 --- a/dwarflint/readctx.c +++ b/dwarflint/readctx.c @@ -320,13 +320,13 @@ read_ctx_eof (struct read_ctx *ctx) bool read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, - int *offset_sizep, struct where *wh) + int *offset_sizep, struct where *where) { if (size32 == DWARF3_LENGTH_64_BIT) { if (!read_ctx_read_8ubyte (ctx, sizep)) { - wr_error (wh, ": can't read 64bit CU length.\n"); + wr_error (where, ": can't read 64bit CU length.\n"); return false; } @@ -334,7 +334,7 @@ read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, } else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE) { - wr_error (wh, ": unrecognized CU length escape value: " + wr_error (where, ": unrecognized CU length escape value: " "%" PRIx32 ".\n", size32); return false; } @@ -346,3 +346,36 @@ read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, return true; } + +bool +read_address_size (struct read_ctx *ctx, + bool addr_64, + int *address_sizep, + struct where const *where) +{ + uint8_t address_size; + if (!read_ctx_read_ubyte (ctx, &address_size)) + { + wr_error (where, ": can't read address size.\n"); + return false; + } + + if (address_size != 4 && address_size != 8) + { + /* Keep going. Deduce the address size from ELF header, and try + to parse it anyway. */ + wr_error (where, + ": invalid address size: %d (only 4 or 8 allowed).\n", + address_size); + address_size = addr_64 ? 8 : 4; + } + else if ((address_size == 8) != addr_64) + /* Keep going, we may still be able to parse it. */ + wr_error (where, + ": CU reports address size of %d in %d-bit ELF.\n", + address_size, addr_64 ? 64 : 32); + + *address_sizep = address_size; + return true; +} + diff --git a/dwarflint/readctx.h b/dwarflint/readctx.h index 8f7b63642..d6f94bf8e 100644 --- a/dwarflint/readctx.h +++ b/dwarflint/readctx.h @@ -76,10 +76,16 @@ bool read_ctx_skip (struct read_ctx *ctx, uint64_t len); bool read_ctx_eof (struct read_ctx *ctx); /* The following procedures build on the ones above and do their own - error reporting. */ + error reporting in addition. */ bool read_size_extra (struct read_ctx *ctx, uint32_t size32, - uint64_t *sizep, int *offset_sizep, struct where *wh); + uint64_t *sizep, int *offset_sizep, + struct where *where); + +bool read_address_size (struct read_ctx *ctx, + bool addr_64, + int *address_sizep, + struct where const *where); #ifdef __cplusplus }