Pull new changes

This commit is contained in:
Jeremy 2024-02-07 21:30:12 -06:00
parent 71090c680b
commit 5c0cb251f9
No known key found for this signature in database
GPG Key ID: BE03111EB7ED6E2E
62 changed files with 1196 additions and 752 deletions

66
CMakeLists.txt vendored
View File

@ -1,11 +1,14 @@
cmake_minimum_required(VERSION 3.5)
project(libdwarf C CXX)
project(libdwarf VERSION 0.9.1 LANGUAGES C CXX)
# libdwarf
option(BUILD_NON_SHARED "build archive library libdwarf[p].a" TRUE)
option(BUILD_SHARED
"build shared library libdwarf[p].so and use it" FALSE)
option(BUILD_SHARED "build shared library libdwarf[p].so and use it" FALSE)
option(ENABLE_DECOMPRESSION
"Enables support for compressed debug sections if both libz/libzstd are present"
TRUE)
# This adds compiler option -Wall (gcc compiler warnings)
option(WALL "Add -Wall" FALSE)
@ -116,7 +119,7 @@ include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckSymbolExists)
### Version also appears in configure.ac
set(VERSION 0.9.0)
set(VERSION 0.9.2)
set(PACKAGE_VERSION "\"${VERSION}\"")
set(PACKAGE_NAME "libdwarf" )
set(PACKAGE_STRING "\"${PACKAGE_NAME} ${VERSION}\"")
@ -179,15 +182,50 @@ else()
message(STATUS "intptr_t value considered NO ")
endif()
# Zlib and ZSTD need to be found otherwise disable it
find_package(ZLIB)
find_package(ZSTD)
if (ZLIB_FOUND AND ZSTD_FOUND )
set(HAVE_ZLIB TRUE)
set(HAVE_ZLIB_H TRUE)
set(HAVE_ZSTD TRUE)
set(HAVE_ZSTD_H TRUE)
endif()
if (ENABLE_DECOMPRESSION)
# Zlib and ZSTD need to be found otherwise disable it
if(NOT TARGET ZLIB::ZLIB)
find_package(ZLIB)
else()
# Presumably in this case, the target has been found externally but set this flag just in case
set(ZLIB_FOUND TRUE)
endif()
# This feels excessive, however perhaps better safe than sorry
if(
NOT (
TARGET zstd::libzstd_shared OR
TARGET zstd::libzstd_static OR
TARGET libzstd_shared OR
TARGET libzstd_static OR
TARGET ZSTD::ZSTD
)
)
find_package(ZSTD)
else()
# Presumably in this case, the target has been found externally but set this flag just in case
set(ZSTD_FOUND TRUE)
endif()
# Unfortunately aliasing ZSTD::ZSTD to zstd::libzstd_shared/static can lead to problems for end-users, a variable
# is used
if(TARGET zstd::libzstd_shared)
set(ZSTD_LIB zstd::libzstd_shared)
elseif(TARGET zstd::libzstd_static)
set(ZSTD_LIB zstd::libzstd_static)
elseif(TARGET libzstd_shared)
set(ZSTD_LIB libzstd_shared)
elseif(TARGET libzstd_static)
set(ZSTD_LIB libzstd_static)
else()
set(ZSTD_LIB ZSTD::ZSTD)
endif()
if (ZLIB_FOUND AND ZSTD_FOUND )
set(HAVE_ZLIB TRUE)
set(HAVE_ZLIB_H TRUE)
set(HAVE_ZSTD TRUE)
set(HAVE_ZSTD_H TRUE)
set(BUILT_WITH_ZLIB_AND_ZSTD TRUE)
endif()
endif ()
message(STATUS "CMAKE_SIZEOF_VOID_P ... " ${CMAKE_SIZEOF_VOID_P} )
@ -216,6 +254,8 @@ else()
set(BUILD_SHARED_LIBS YES)
endif()
include(GNUInstallDirs)
add_subdirectory(src/lib/libdwarf)
if ( BUILD_DWARFDUMP )

View File

@ -6,7 +6,8 @@ echo "Fetching"
git clone https://github.com/davea42/libdwarf-code.git
cd libdwarf-code
#git checkout "6216e185863f41d6f19ab850caabfff7326020d7" # v0.8.0
git checkout "8b0bd09d8c77d45a68cb1bb00a54186a92b683d9" # v0.9.0
#git checkout "8b0bd09d8c77d45a68cb1bb00a54186a92b683d9" # v0.9.0
git checkout "8cdcc531f310d1c5ae61da469d8056bdd36b77e7" # v0.9.1 + cmake fixes
cd ..
echo "Copying files"
mkdir -p src/lib

View File

@ -29,6 +29,7 @@ dwarf_rnglists.c
dwarf_safe_arithmetic.c
dwarf_safe_strcpy.c
dwarf_secname_ck.c
dwarf_seekr.c
dwarf_setup_sections.c
dwarf_string.h dwarf_string.c
dwarf_stringsection.c
@ -89,9 +90,6 @@ if (PIC_ALWAYS)
list(APPEND DEFS PIC)
endif()
include(GNUInstallDirs)
if(BUILD_SHARED)
add_library(dwarf SHARED ${SOURCES} ${HEADERS} ${CONFIGURATION_FILES})
add_library(libdwarf::dwarf-shared ALIAS dwarf)
@ -108,43 +106,34 @@ target_include_directories(dwarf PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(ZLIB_FOUND AND ZSTD_FOUND)
target_link_libraries(dwarf PRIVATE ZLIB::ZLIB ZSTD::ZSTD )
target_link_libraries(dwarf PRIVATE ZLIB::ZLIB ${ZSTD_LIB} )
endif()
set(SUFFIX $<$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>:64>)
set(LIBDIR lib${SUFFIX})
set(BINDIR bin${SUFFIX})
set_target_properties(dwarf PROPERTIES PUBLIC_HEADER "libdwarf.h;dwarf.h")
install(TARGETS dwarf
RUNTIME DESTINATION ${BINDIR}
LIBRARY DESTINATION ${LIBDIR}
ARCHIVE DESTINATION ${LIBDIR})
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
configure_file(libdwarf.pc.cmake libdwarf.pc @ONLY )
configure_file(libdwarf.pc.cmake libdwarf.pc @ONLY)
# The install has to be here, not in
# another CMakeLists.txt to make install work properly
# for cmake before cmake 3.13. This also works
# for newer cmake.
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libdwarfConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/libdwarfConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libdwarf")
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/libdwarfConfigVersion.cmake" COMPATIBILITY SameMinorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libdwarfConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libdwarfConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libdwarf")
install(TARGETS dwarf EXPORT libdwarfTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(EXPORT libdwarfTargets
FILE libdwarf-targets.cmake
NAMESPACE libdwarf::
DESTINATION lib/cmake/libdwarf
)
install(
FILES cmake/libdwarf-config.cmake
DESTINATION lib/cmake/libdwarf
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/libdwarf.h
DESTINATION include/libdwarf)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/dwarf.h
DESTINATION include/libdwarf)
install( FILES ${PROJECT_BINARY_DIR}/src/lib/libdwarf/libdwarf.pc
DESTINATION lib/pkgconfig
)
FILE libdwarf-targets.cmake
NAMESPACE libdwarf::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libdwarf")
install(FILES "${PROJECT_BINARY_DIR}/src/lib/libdwarf/libdwarf.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES "${PROJECT_SOURCE_DIR}/cmake/FindZSTD.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libdwarf")

View File

@ -94,6 +94,7 @@ dwarf_safe_strcpy.c \
dwarf_safe_strcpy.h \
dwarf_secname_ck.c \
dwarf_secname_ck.h \
dwarf_seekr.c \
dwarf_setup_sections.c \
dwarf_setup_sections.h \
dwarf_ranges.c \
@ -155,7 +156,7 @@ CODINGSTYLE \
dw-linetableheader.txt \
CMakeLists.txt \
libdwarf.pc.cmake \
cmake/libdwarf-config.cmake \
cmake/libdwarfConfig.cmake.in \
meson.build \
NEWS \
README \

View File

@ -1,3 +0,0 @@
if (NOT TARGET libdwarf::libdwarf)
include(${CMAKE_CURRENT_LIST_DIR}/libdwarf-targets.cmake)
endif()

View File

@ -0,0 +1,18 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
set(LIBDWARF_BUILT_WITH_ZLIB_AND_ZSTD "@BUILT_WITH_ZLIB_AND_ZSTD@")
if(LIBDWARF_BUILT_WITH_ZLIB_AND_ZSTD)
find_dependency(ZLIB)
set(CMAKE_MODULE_PATH_OLD "${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_LIST_DIR}")
find_dependency(ZSTD)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH_OLD}")
unset(CMAKE_MODULE_PATH_OLD)
endif()
if(NOT TARGET libdwarf::dwarf)
include(${CMAKE_CURRENT_LIST_DIR}/libdwarf-targets.cmake)
check_required_components(libdwarf)
endif()

View File

@ -154,9 +154,19 @@ extern "C" {
#define DW_TAG_call_site_parameter 0x49 /* DWARF5 */
#define DW_TAG_skeleton_unit 0x4a /* DWARF5 */
#define DW_TAG_immutable_type 0x4b /* DWARF5 */
#define DW_TAG_lo_user 0x4080
/* TI = Texas Instruments, for DWARF in COFF */
/* https://www.ti.com/lit/an/spraab5/spraab5.pdf?ts=1705994928599 */
#define DW_TAG_lo_user 0x4080 /* TI */
#define DW_TAG_TI_far_type 0x4080 /* TI */
#define DW_TAG_MIPS_loop 0x4081
#define DW_TAG_TI_near_type 0x4081 /* TI */
#define DW_TAG_TI_assign_register 0x4082 /* TI */
#define DW_TAG_TI_ioport_type 0x4083 /* TI */
#define DW_TAG_TI_restrict_type 0x4084 /* TI */
#define DW_TAG_TI_onchip_type 0x4085 /* TI */
/* HP extensions: ftp://ftp.hp.com/pub/lang/tools/\
WDB/wdb-4.0.tar.gz */
@ -448,14 +458,15 @@ extern "C" {
/* In extensions, we attempt to include the vendor extension
in the name even when the vendor leaves it out. */
/* HP extensions. */
#define DW_AT_HP_block_index 0x2000 /* HP */
#define DW_AT_TI_veneer 0x2000 /* TI */
/* 0x2000 Follows extension so dwarfdump prints the
most-likely-useful name. */
#define DW_AT_lo_user 0x2000
#define DW_AT_MIPS_fde 0x2001 /* MIPS/SGI */
#define DW_AT_TI_symbol_name 0x2001 /* TI */
#define DW_AT_MIPS_loop_begin 0x2002 /* MIPS/SGI */
#define DW_AT_MIPS_tail_loop_begin 0x2003 /* MIPS/SGI */
#define DW_AT_MIPS_epilog_begin 0x2004 /* MIPS/SGI */
@ -466,12 +477,16 @@ extern "C" {
#define DW_AT_MIPS_abstract_name 0x2009 /* MIPS/SGI */
#define DW_AT_MIPS_clone_origin 0x200a /* MIPS/SGI */
#define DW_AT_MIPS_has_inlines 0x200b /* MIPS/SGI */
#define DW_AT_TI_version 0x200b /* TI */
#define DW_AT_MIPS_stride_byte 0x200c /* MIPS/SGI */
#define DW_AT_TI_asm 0x200c /* TI */
#define DW_AT_MIPS_stride_elem 0x200d /* MIPS/SGI */
#define DW_AT_MIPS_ptr_dopetype 0x200e /* MIPS/SGI */
#define DW_AT_TI_skeletal 0x200e /* TI */
#define DW_AT_MIPS_allocatable_dopetype 0x200f /* MIPS/SGI */
#define DW_AT_MIPS_assumed_shape_dopetype 0x2010 /* MIPS/SGI */
#define DW_AT_MIPS_assumed_size 0x2011 /* MIPS/SGI */
#define DW_AT_TI_interrupt 0x2011 /* TI */
/* HP extensions. */
#define DW_AT_HP_unmodifiable 0x2001 /* conflict: MIPS */
@ -1003,6 +1018,9 @@ most-likely-useful name. */
#define DW_IDX_GNU_internal 0x2000
#define DW_IDX_lo_user 0x2000 /* DWARF5 */
#define DW_IDX_GNU_external 0x2001
#define DW_IDX_GNU_main 0x2002
#define DW_IDX_GNU_language 0x2003
#define DW_IDX_GNU_linkage_name 0x2004
#define DW_IDX_hi_user 0x3fff /* DWARF5 */
/* These with not-quite-the-same-names were used in DWARF4
@ -1173,14 +1191,20 @@ most-likely-useful name. */
#define DW_LANG_Assembly 0x0031 /* DWARF6 */
#define DW_LANG_C_sharp 0x0032 /* DWARF6 */
#define DW_LANG_Mojo 0x0033 /* DWARF6 */
#define DW_LANG_GLSL 0x0034 /* DWARF6 */
#define DW_LANG_GLSL_ES 0x0035 /* DWARF6 */
#define DW_LANG_HLSL 0x0036 /* DWARF6 */
#define DW_LANG_OpenCL_CPP 0x0037 /* DWARF6 */
#define DW_LANG_CPP_for_OpenCL 0x0038 /* DWARF6 */
#define DW_LANG_SYCL 0x0039 /* DWARF6 */
#define DW_LANG_Ruby 0x0040 /* DWARF6 */
#define DW_LANG_lo_user 0x8000
#define DW_LANG_Mips_Assembler 0x8001 /* MIPS */
#define DW_LANG_Upc 0x8765 /* UPC, use
DW_LANG_UPC instead. */
#define DW_LANG_GOOGLE_RenderScript 0x8e57
/* ALTIUM extension */
#define DW_LANG_ALTIUM_Assembler 0x9101 /* ALTIUM */
#define DW_LANG_ALTIUM_Assembler 0x9101
#define DW_LANG_BORLAND_Delphi 0xb000
/* Sun extensions */
@ -1381,11 +1405,13 @@ most-likely-useful name. */
#define DW_CFA_val_offset 0x14 /* DWARF3f */
#define DW_CFA_val_offset_sf 0x15 /* DWARF3f */
#define DW_CFA_val_expression 0x16 /* DWARF3f */
#define DW_CFA_lo_user 0x1c
#define DW_CFA_lo_user 0x1c
#define DW_CFA_TI_soffset_extended 0x1c /* TI */
#define DW_CFA_low_user 0x1c /* Incorrect spelling, do not use. */
/* SGI/MIPS extension. */
#define DW_CFA_MIPS_advance_loc8 0x1d /* MIPS */
#define DW_CFA_MIPS_advance_loc8 0x1d /* MIPS */
#define DW_CFA_TI_def_cfa_soffset 0x1d /* TI */
/* GNU extensions. */
#define DW_CFA_GNU_window_save 0x2d /* GNU */
@ -1577,6 +1603,12 @@ most-likely-useful name. */
#define DW_CHILDREN_yes 0x01
#define DW_ADDR_none 0
#define DW_ADDR_TI_PTR8 0x0008 /* TI */
#define DW_ADDR_TI_PTR16 0x0010 /* TI */
#define DW_ADDR_TI_PTR22 0x0016 /* TI */
#define DW_ADDR_TI_PTR23 0x0017 /* TI */
#define DW_ADDR_TI_PTR24 0x0018 /* TI */
#define DW_ADDR_TI_PTR32 0x0020 /* TI */
#ifdef __cplusplus
}

View File

@ -460,7 +460,7 @@ dwarf_get_aranges(Dwarf_Debug dbg,
return DW_DLV_OK;
}
#if 0
#if 0 /* _dwarf_get_aranges_addr_offsets Unused */
/*
This function returns DW_DLV_OK if it succeeds
and DW_DLV_ERR or DW_DLV_OK otherwise.

View File

@ -118,6 +118,9 @@ static const uint32_t crc32_table[256] =
language but English) and the following is a translation
into C. Just like every other crc calculation.
There is no error indicated if buf does not point
to a readable area of memory at least len bytes long!
The unsigned int return will not get the same CRC as
Linux/Macos if int/unsigned-int is 16 bits (Windows),
but there the crc does not matter in practice.
@ -129,7 +132,10 @@ dwarf_basic_crc32 (const unsigned char *buf,
unsigned int crc)
{
const unsigned char *end = 0;
if (!buf) {
return 0;
}
crc = ~crc;
for (end = buf + len; buf < end; ++buf)
crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);

View File

@ -1,4 +1,5 @@
/*
Copyright (C) 2020 David Anderson. All Rights Reserved.
This program is free software; you can redistribute it
@ -32,15 +33,6 @@
#include <stdlib.h> /* free() malloc() */
#include <string.h> /* memcpy() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* lseek() off_t ssize_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* lseek() off_t */
#endif /* _WIN32 */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -57,24 +49,36 @@
The crc is calculated based on reading
the entire current open
Dwarf_Debug dbg object file and all bytes in
the file are read to create the crc. */
the file are read to create the crc.
In Windows, where unsigned int is 16 bits, this
produces different output than on 32bit ints.
Since lseek() (all systems/versions) returns
a signed value, we check for < 0 as error
rather than just check for -1. So it is clear
to symbolic exectution that conversion to
unsigned does not lose bits.
*/
int
dwarf_crc32 (Dwarf_Debug dbg,unsigned char *crcbuf,
Dwarf_Error *error)
{
/* off_t is signed, defined by POSIX */
/* ssize_t is signed, defined in POSIX */
/* size_t is unsigned, defined in C89. */
off_t size_left = 0;
off_t fsize = 0;
off_t lsval = 0;
Dwarf_Unsigned fsize = 0;
/* Named with u to remind the reader that this is
an unsigned value. */
size_t readlenu = 1000;
unsigned char *readbuf = 0;
Dwarf_Unsigned readlenu = 10000;
Dwarf_Unsigned size_left = 0;
const unsigned char *readbuf = 0;
unsigned int tcrc = 0;
unsigned int init = 0;
int fd = -1;
Dwarf_Unsigned sz = 0;
int res = 0;
CHECK_DBG(dbg,error,"dwarf_crc32()");
if (!crcbuf) {
@ -89,23 +93,25 @@ dwarf_crc32 (Dwarf_Debug dbg,unsigned char *crcbuf,
}
fd = dbg->de_fd;
if (dbg->de_filesize) {
fsize = size_left = (off_t)dbg->de_filesize;
fsize = (size_t)dbg->de_filesize;
} else {
fsize = size_left = lseek(fd,0L,SEEK_END);
if (fsize == (off_t)-1) {
res = _dwarf_seekr(fd,0,SEEK_END,&sz);
if (res != DW_DLV_OK) {
_dwarf_error_string(dbg,error,DW_DLE_SEEK_ERROR,
"DW_DLE_SEEK_ERROR: dwarf_crc32 seek "
"to end fails");
return DW_DLV_ERROR;
}
fsize = sz;
}
if (fsize <= (off_t)500) {
if (fsize <= (Dwarf_Unsigned)500) {
/* Not a real object file.
A random length check. */
return DW_DLV_NO_ENTRY;
}
lsval = lseek(fd,0L,SEEK_SET);
if (lsval < 0) {
size_left = fsize;
res = _dwarf_seekr(fd,0,SEEK_SET,0);
if (res != DW_DLV_OK) {
_dwarf_error_string(dbg,error,DW_DLE_SEEK_ERROR,
"DW_DLE_SEEK_ERROR: dwarf_crc32 seek "
"to start fails");
@ -119,32 +125,25 @@ dwarf_crc32 (Dwarf_Debug dbg,unsigned char *crcbuf,
return DW_DLV_ERROR;
}
while (size_left > 0) {
ssize_t readreturnv = 0;
if (size_left < (off_t)readlenu) {
readlenu = (size_t)size_left;
if (size_left < readlenu) {
readlenu = size_left;
}
/* Fix warning on Windows: read()'s
3rd parameter is a unsigned const */
#ifdef _WIN32
readreturnv = read(fd,readbuf,(unsigned const)readlenu);
#else
readreturnv = read(fd,readbuf,readlenu);
#endif
if (readreturnv != (ssize_t)readlenu) {
res = _dwarf_readr(fd,(char *)readbuf,readlenu,0);
if (res != DW_DLV_OK) {
_dwarf_error_string(dbg,error,DW_DLE_READ_ERROR,
"DW_DLE_READ_ERROR: dwarf_crc32 read fails ");
free(readbuf);
free((unsigned char*)readbuf);
return DW_DLV_ERROR;
}
/* Call the public API function so it gets tested too. */
tcrc = dwarf_basic_crc32(readbuf,readlenu,
tcrc = (unsigned int)dwarf_basic_crc32(readbuf,
(unsigned long)readlenu,
(unsigned long)init);
init = tcrc;
size_left -= (off_t)readlenu;
size_left -= readlenu;
}
/* endianness issues? */
free(readbuf);
free((unsigned char*)readbuf);
memcpy(crcbuf,(void *)&tcrc,4);
return DW_DLV_OK;
}

View File

@ -51,7 +51,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dwarf_debugaddr.h"
#include "dwarf_string.h"
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{

View File

@ -61,10 +61,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include "dwarf_string.h"
#include "dwarf_debuglink.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#define MINBUFLEN 1000
static char joinchar = '/';
@ -413,7 +409,7 @@ build_buildid_filename(dwarfstring *target,
return;
}
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,unsigned char * start, unsigned len)
{
@ -987,7 +983,6 @@ dwarf_gnu_debuglink(Dwarf_Debug dbg,
return res;
}
}
if (!pdebuglink && !pbuildid) {
if (dbg->de_path) {
*debuglink_fullpath_returned = strdup(dbg->de_path);

View File

@ -52,7 +52,7 @@
#include "dwarf_debugnames.h"
#include "dwarf_string.h"
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -66,7 +66,7 @@ dump_bytes(char * msg,Dwarf_Small * start, long len)
printf("\n");
}
#endif /*0*/
#if 0
#if 0 /* dump_abbrev_record() */
static void
dump_abbrev_record(const char *msg,
Dwarf_Unsigned abcode,

View File

@ -63,6 +63,7 @@ static void assign_correct_unit_type(Dwarf_CU_Context cu_context);
static int find_cu_die_base_fields(Dwarf_Debug dbg,
Dwarf_CU_Context cucon,
Dwarf_Die cudie,
Dwarf_Bool *bad_pc_form,
Dwarf_Error *error);
static int _dwarf_siblingof_internal(Dwarf_Debug dbg,
@ -80,7 +81,7 @@ static int _dwarf_siblingof_internal(Dwarf_Debug dbg,
static struct Dwarf_Sig8_s dwarfsig8zero;
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -600,19 +601,24 @@ finish_cu_context_via_cudie_inner(
&cudie, error);
if (resdwo == DW_DLV_OK) {
Dwarf_Half cutag = 0;
Dwarf_Bool bad_pc_form = FALSE;
int resdwob = 0;
resdwob = find_cu_die_base_fields(dbg,
cu_context,
cudie,
cudie, &bad_pc_form,
error);
if (resdwob == DW_DLV_NO_ENTRY) {
/* The CU die has no children */
/* The CU die has no children or has
some other issue like DW_FORM_ref_addr
on a low or high pc attribute. (Metrowerks) */
if (local_cudie_return) {
*local_cudie_return = cudie;
} else {
dwarf_dealloc_die(cudie);
}
cu_context->cc_cu_die_has_children = FALSE;
if (!bad_pc_form) {
cu_context->cc_cu_die_has_children = FALSE;
}
return DW_DLV_OK;
}
if (resdwob == DW_DLV_ERROR) {
@ -1078,6 +1084,7 @@ _dwarf_setup_base_address(Dwarf_Debug dbg,
Dwarf_Attribute attr,
Dwarf_Signed at_addr_base_attrnum,
Dwarf_CU_Context cucon,
Dwarf_Bool *bad_pc_form,
Dwarf_Error *error)
{
int lres = 0;
@ -1107,6 +1114,15 @@ _dwarf_setup_base_address(Dwarf_Debug dbg,
return DW_DLV_ERROR;
}
}
if (form == DW_FORM_ref_addr) {
/* The old Macrowerks compiler did this
from confusion vs DW_FORM_addr.
Lets just say it is not good rather
than generating an error.
*/
*bad_pc_form = TRUE;
return DW_DLV_NO_ENTRY;
}
lres = dwarf_formaddr(attr,
&cucon->cc_low_pc,error);
if (lres == DW_DLV_OK) {
@ -1121,6 +1137,68 @@ _dwarf_setup_base_address(Dwarf_Debug dbg,
return lres;
}
static void
_dwarf_set_children_flag(Dwarf_CU_Context cucon,
Dwarf_Die cudie)
{
int chres = 0;
Dwarf_Half flag = 0;
/* always winds up with cc_cu_die_has_children
set intentionally...to something. */
cucon->cc_cu_die_has_children = TRUE;
chres = dwarf_die_abbrev_children_flag(cudie,&flag);
/* If chres is not DW_DLV_OK the assumption
of children remains true. */
if (chres == DW_DLV_OK) {
cucon->cc_cu_die_has_children = flag;
}
}
static int
_dwarf_prod_contains(const char *ck, const char *prod)
{
const char *cp = prod;
size_t len = strlen(ck);
for( ; *cp ; ++cp) {
if ( ck[0] != *cp) {
continue;
}
if (strncmp(ck,cp,len)) {
continue;
}
return TRUE;
}
return FALSE;
}
/* Here we make an effort to determine if it is
Metrowerks C */
static void
set_producer_type(Dwarf_Die die,
Dwarf_CU_Context cu_context)
{
int res = 0;
Dwarf_Error error = 0;
char *producer = 0;
res = dwarf_die_text(die,DW_AT_producer,&producer,&error);
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(cu_context->cc_dbg,error);
error = 0;
return;
}
if (res == DW_DLV_NO_ENTRY) {
return;
}
if (_dwarf_prod_contains("Metrowerks",producer)) {
cu_context->cc_producer = CC_PROD_METROWERKS;
}
}
/*
For a DWP/DWO the base fields
of a CU are inherited from the skeleton.
@ -1131,6 +1209,7 @@ static int
find_cu_die_base_fields(Dwarf_Debug dbg,
Dwarf_CU_Context cucon,
Dwarf_Die cudie,
Dwarf_Bool *bad_pc_form,
Dwarf_Error* error)
{
Dwarf_CU_Context cu_context = 0;
@ -1191,10 +1270,14 @@ find_cu_die_base_fields(Dwarf_Debug dbg,
case DW_FORM_strx3:
case DW_FORM_strx4:
cucon->cc_at_strx_present = TRUE;
break;
default:
break;
}
switch(attrnum) {
case DW_AT_producer:
set_producer_type(cudie,cu_context);
break;
case DW_AT_dwo_id:
case DW_AT_GNU_dwo_id: {
Dwarf_Sig8 signature;
@ -1409,10 +1492,13 @@ find_cu_die_base_fields(Dwarf_Debug dbg,
/* Prefer DW_AT_low_pc */
Dwarf_Attribute attr = alist[low_pc_attrnum];
battr = _dwarf_setup_base_address(dbg,"DW_AT_low_pc",
attr,at_addr_base_attrnum, cucon,error);
attr,at_addr_base_attrnum, cucon,
bad_pc_form,error);
if (battr != DW_DLV_OK) {
local_attrlist_dealloc(dbg,atcount,alist);
/* Something is badly wrong */
/* Something is wrong, possibly
erroneous Macrowerks compiler. */
_dwarf_set_children_flag(cucon,cudie);
return battr;
}
} else if (entry_pc_attrnum >= 0) {
@ -1429,30 +1515,19 @@ find_cu_die_base_fields(Dwarf_Debug dbg,
no DW_AT_low_pc. 19 May 2022. */
Dwarf_Attribute attr = alist[entry_pc_attrnum];
battr = _dwarf_setup_base_address(dbg,"DW_AT_entry_pc",
attr,at_addr_base_attrnum, cucon,error);
attr,at_addr_base_attrnum, cucon,
bad_pc_form,error);
if (battr != DW_DLV_OK) {
local_attrlist_dealloc(dbg,atcount,alist);
/* Something is badly wrong */
/* Something is wrong */
_dwarf_set_children_flag(cucon,cudie);
return battr;
}
}
local_attrlist_dealloc(dbg,atcount,alist);
alist = 0;
atcount = 0;
{
int chres = 0;
Dwarf_Half flag = 0;
/* always winds up with cc_cu_die_has_children
set intentionally...to something. */
cucon->cc_cu_die_has_children = TRUE;
chres = dwarf_die_abbrev_children_flag(cudie,&flag);
/* If chres is not DW_DLV_OK the assumption
of children remains true. */
if (chres == DW_DLV_OK) {
cucon->cc_cu_die_has_children = flag;
}
}
_dwarf_set_children_flag(cucon,cudie);
return DW_DLV_OK;
}
@ -2074,7 +2149,7 @@ _dwarf_ptr_CU_offset(Dwarf_CU_Context cu_context,
*cu_off = (di_ptr - dataptr);
return DW_DLV_OK;
}
#if 0 /* FOR DEBUGGING */
#if 0 /* print_sib_offset() for debugging */
/* Just for debug purposes */
void print_sib_offset(Dwarf_Die sibling)
{

View File

@ -984,6 +984,9 @@ extern "C" {
#ifndef R_386_32
#define R_386_32 1
#endif /* R_386_32 */
#ifndef R_386_GOTOFF
#define R_386_GOTOFF 9
#endif /* R_386_GOTOFF */
#ifndef R_386_GOTPC
#define R_386_GOTPC 10
#endif /* R_386_GOTPC */

View File

@ -53,22 +53,10 @@ calls
#include <stddef.h> /* size_t */
#include <stdlib.h> /* calloc() free() malloc() */
#include <stdio.h> /* printf debugging */
#include <string.h> /* memcpy() strcmp() strdup()
strlen() strncmp() */
/* Windows specific header files */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* close() off_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* close() */
#endif /* _WIN32 */
#ifdef HAVE_FCNTL_H
#include <fcntl.h> /* open() O_RDONLY */
#endif /* HAVE_FCNTL_H */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -84,14 +72,7 @@ calls
#include "dwarf_util.h"
#include "dwarf_secname_ck.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif /* O_CLOEXEC */
#if 0
#if 0 /* debugging only dumpsizes() */
/* One example of calling this.
place just before DW_DLE_SECTION_SIZE_OR_OFFSET_LARGE
dumpsizes(__LINE__,strsectlength,strpsh->gh_offset,
@ -132,6 +113,7 @@ getbitsoncount(Dwarf_Unsigned v_in)
static int
_dwarf_load_elf_section_is_dwarf(const char *sname,
Dwarf_Unsigned sectype,
int *is_rela,int *is_rel)
{
*is_rel = FALSE;
@ -139,6 +121,10 @@ _dwarf_load_elf_section_is_dwarf(const char *sname,
if (_dwarf_ignorethissection(sname)) {
return FALSE;
}
if (sectype == SHT_RELA) {
*is_rela = TRUE;
return TRUE;
}
if (!strncmp(sname,".rel",4)) {
if (!strncmp(sname,".rela.",6)) {
*is_rela = TRUE;
@ -201,8 +187,11 @@ generic_ehdr_from_32(dwarf_elf_object_access_internals_t *ep,
ASNAR(ep->f_copy_word,ehdr->ge_shentsize,e->e_shentsize);
ASNAR(ep->f_copy_word,ehdr->ge_shnum,e->e_shnum);
ASNAR(ep->f_copy_word,ehdr->ge_shstrndx,e->e_shstrndx);
if (!ehdr->ge_shoff) {
return DW_DLV_NO_ENTRY;
}
if (ehdr->ge_shoff < sizeof(dw_elf32_ehdr)) {
/* zero or offset is inside the header! */
/* offset is inside the header! */
*errcode = DW_DLE_TOO_FEW_SECTIONS;
return DW_DLV_ERROR;
}
@ -221,6 +210,9 @@ generic_ehdr_from_32(dwarf_elf_object_access_internals_t *ep,
ehdr->ge_shnum_extended = TRUE;
} else {
ehdr->ge_shnum_in_shnum = TRUE;
if (!ehdr->ge_shnum) {
return DW_DLV_NO_ENTRY;
}
if (ehdr->ge_shnum < 3) {
*errcode = DW_DLE_TOO_FEW_SECTIONS;
return DW_DLV_ERROR;
@ -266,6 +258,9 @@ generic_ehdr_from_64(dwarf_elf_object_access_internals_t* ep,
ASNAR(ep->f_copy_word,ehdr->ge_shentsize,e->e_shentsize);
ASNAR(ep->f_copy_word,ehdr->ge_shnum,e->e_shnum);
ASNAR(ep->f_copy_word,ehdr->ge_shstrndx,e->e_shstrndx);
if (!ehdr->ge_shoff) {
return DW_DLV_NO_ENTRY;
}
if (ehdr->ge_shoff < sizeof(dw_elf64_ehdr)) {
/* zero or offset is inside the header! */
*errcode = DW_DLE_TOO_FEW_SECTIONS;
@ -284,6 +279,9 @@ generic_ehdr_from_64(dwarf_elf_object_access_internals_t* ep,
ehdr->ge_shnum_extended = TRUE;
} else {
ehdr->ge_shnum_in_shnum = TRUE;
if (!ehdr->ge_shnum) {
return DW_DLV_NO_ENTRY;
}
if (ehdr->ge_shnum < 3) {
*errcode = DW_DLE_TOO_FEW_SECTIONS;
return DW_DLV_ERROR;
@ -305,7 +303,7 @@ generic_ehdr_from_64(dwarf_elf_object_access_internals_t* ep,
return DW_DLV_OK;
}
#if 0 /* not used */
#if 0 /* ngeneric_phdr_from_phdr32 not needed */
static int
generic_phdr_from_phdr32(dwarf_elf_object_access_internals_t* ep,
struct generic_phdr **phdr_out,
@ -844,7 +842,7 @@ _dwarf_generic_elf_load_symbols(
}
return res;
}
#if 0 /* not needed */
#if 0 /* dwarf_load_elf_dynsym_symbols() not needed */
int
dwarf_load_elf_dynsym_symbols(
dwarf_elf_object_access_internals_t *ep, int*errcode)
@ -1079,7 +1077,7 @@ generic_rel_from_rel64(
return DW_DLV_OK;
}
#if 0 /* not needed */
#if 0 /* dwarf_load_elf_dynstr() not needed */
int
dwarf_load_elf_dynstr(
dwarf_elf_object_access_internals_t *ep, int *errcode)
@ -1788,7 +1786,7 @@ elf_load_elf_header32(
free(ehdr);
return res;
}
ep->f_machine = ehdr->ge_machine;
ep->f_machine = (unsigned)ehdr->ge_machine;
ep->f_flags = ehdr->ge_flags;
return res;
}
@ -1817,7 +1815,7 @@ elf_load_elf_header64(
free(ehdr);
return res;
}
ep->f_machine = ehdr->ge_machine;
ep->f_machine = (unsigned)ehdr->ge_machine;
ep->f_flags = ehdr->ge_flags;
return res;
}
@ -2135,6 +2133,7 @@ _dwarf_elf_setup_all_section_groups(
psh->gh_section_group_number = DW_GROUPNUMBER_DWO;
ep->f_dwo_group_section_count++;
} else if (_dwarf_load_elf_section_is_dwarf(name,
psh->gh_type,
&is_rela,&is_rel)) {
if (!psh->gh_section_group_number) {
psh->gh_section_group_number = DW_GROUPNUMBER_BASE;

View File

@ -88,6 +88,9 @@ _dwarf_is_32bit_abs_reloc(unsigned int type, unsigned machine)
#if defined (R_386_32)
| (type == R_386_32)
#endif
#if defined (R_386_GOTOFF)
| (type == R_386_GOTOFF)
#endif
#if defined (R_386_GOTPC)
| (type == R_386_GOTPC)
#endif

View File

@ -66,15 +66,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h> /* debug printf */
#include <string.h> /* memset() strdup() strncmp() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* close() off_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* close() off_t */
#endif /* _WIN32*/
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -252,9 +243,9 @@ elf_load_nolibelf_section (void *obj, Dwarf_Unsigned section_index,
read_size = read_size_limit;
}
res = RRMOA(elf->f_fd,
(void *)read_target, (off_t)read_offset,
(size_t)read_size,
(off_t)elf->f_filesize, error);
(void *)read_target, read_offset,
read_size,
elf->f_filesize, error);
if (res != DW_DLV_OK) {
free(sp->gh_content);
sp->gh_content = 0;
@ -571,7 +562,7 @@ _dwarf_destruct_elf_nlaccess(
/* if TRUE close f_fd on destruct.*/
if (ep->f_destruct_close_fd) {
close(ep->f_fd);
_dwarf_closer(ep->f_fd);
}
ep->f_ident[0] = 'X';
free(ep->f_path);
@ -738,11 +729,13 @@ _dwarf_elf_object_access_internals_init(
as it will be caught elsewhere
if necessary. */
continue;
} else if (section_type == SHT_REL ||
(!strncmp(".rel.",shp->gh_namestring,5))) {
} else if (section_type == SHT_REL) {
localrel = RelocIsRel;
} else if (section_type == SHT_RELA ||
(!strncmp(".rela.",shp->gh_namestring,6))) {
} else if (section_type == SHT_RELA) {
localrel = RelocIsRela;
} else if (!strncmp(".rel.",shp->gh_namestring,5)) {
localrel = RelocIsRel;
} else if (!strncmp(".rela.",shp->gh_namestring,6)) {
localrel = RelocIsRela;
} else {
continue;

View File

@ -181,7 +181,7 @@ _dwarf_fill_in_attr_form_abtable(Dwarf_CU_Context context,
abbrev_list->abl_implicit_const_count++;
abbrev_list->abl_implicit_const[i] = implicit_const;
}
#if 0
#if 0 /* Do nothing special for DW_FORM_indirect here. Ignore. */
if (attr_form == DW_FORM_indirect) {
/* Do nothing special here. Do not read
from the DIE till reading for

View File

@ -44,7 +44,7 @@ Floor, Boston MA 02110-1301, USA.
#include "dwarf_error.h"
#include "dwarf_util.h"
#include "dwarf_string.h"
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,int line,
Dwarf_Small * start, long len)
@ -134,7 +134,7 @@ _dwarf_find_CU_Context_given_sig(Dwarf_Debug dbg,
new_cu_offset =
_dwarf_calculate_next_cu_context_offset(
cu_context)) {
#if 0
#if 0 /* unnecessary load section call, we think. */
lres = _dwarf_load_die_containing_section(dbg,
is_info,error);
if (lres == DW_DLV_ERROR) {

View File

@ -50,7 +50,7 @@
#include "dwarf_die_deliv.h"
#include "dwarf_str_offsets.h"
#include "dwarf_string.h"
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,int line,
Dwarf_Small * start, long len)
@ -432,6 +432,32 @@ dwarf_convert_to_global_offset(Dwarf_Attribute attr,
are not references to .debug_info/.debug_types,
so they are not allowed here. */
static void
show_not_ref_error(Dwarf_Debug dbg,
Dwarf_Error *error,
Dwarf_Half form,
Dwarf_Half attr)
{
dwarfstring m;
const char *fname = 0;
const char *aname = 0;
/*DW_DLE_NOT_REF_FORM */
dwarfstring_constructor(&m);
dwarf_get_FORM_name(form,&fname);
dwarf_get_AT_name(attr,&aname);
dwarfstring_append(&m,"DW_DLE_NOT_REF_FORM: ");
dwarfstring_append(&m,(char *)fname);
dwarfstring_append_printf_s(&m," (on attribute %s )",
(char *)aname);
dwarfstring_append(&m," for versions >= 4 ");
dwarfstring_append(&m,"is not a valid reference form");
_dwarf_error_string(dbg,error,DW_DLE_NOT_REF_FORM,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
}
int
dwarf_formref(Dwarf_Attribute attr,
Dwarf_Off * ret_offset,
@ -492,7 +518,7 @@ dwarf_formref(Dwarf_Attribute attr,
/* We need to look for a local reference here.
The function we are in is only CU_local
offsets returned. */
#if 0
#if 0 /* check for a local sig8 reference unimplemented. */
Dwarf_Sig8 sig8;
memcpy(&sig8,ptr,sizeof(Dwarf_Sig8));
res = dwarf_find_die_given_sig8(dbg,
@ -510,14 +536,20 @@ dwarf_formref(Dwarf_Attribute attr,
}
default: {
dwarfstring m;
const char * fname = 0;
const char * aname = 0;
dwarf_get_FORM_name(attr->ar_attribute_form,&fname);
dwarf_get_AT_name(attr->ar_attribute,&aname);
dwarfstring_constructor(&m);
dwarfstring_append_printf_u(&m,
"DW_DLE_BAD_REF_FORM. The form "
"code is 0x%x which does not have an offset "
" for "
"dwarf_formref() to return.",
"code is 0x%x ",
attr->ar_attribute_form);
dwarfstring_append(&m,(char *)fname);
dwarfstring_append_printf_s(&m," on attribute %s, "
"which does not have an offset"
" for dwarf_formref() to return.",(char *)aname);
_dwarf_error_string(dbg, error, DW_DLE_BAD_REF_FORM,
dwarfstring_string(&m));
dwarfstring_destructor(&m);
@ -802,8 +834,9 @@ _dwarf_internal_global_formref_b(Dwarf_Attribute attr,
That was first clearly documented in DWARF3.
In DWARF4 these two forms are no longer references. */
case DW_FORM_data4:
if (context_version >= DW_CU_VERSION4) {
_dwarf_error(dbg, error, DW_DLE_NOT_REF_FORM);
if (context_version >= DW_CU_VERSION4) {
show_not_ref_error(dbg,error,attr->ar_attribute_form,
attr->ar_attribute);
return DW_DLV_ERROR;
}
READ_UNALIGNED_CK(dbg, offset, Dwarf_Unsigned,
@ -813,7 +846,8 @@ _dwarf_internal_global_formref_b(Dwarf_Attribute attr,
break;
case DW_FORM_data8:
if (context_version >= DW_CU_VERSION4) {
_dwarf_error(dbg, error, DW_DLE_NOT_REF_FORM);
show_not_ref_error(dbg,error,attr->ar_attribute_form,
attr->ar_attribute);
return DW_DLV_ERROR;
}
READ_UNALIGNED_CK(dbg, offset, Dwarf_Unsigned,
@ -1029,7 +1063,7 @@ _dwarf_get_addr_index_itself(int theform,
if the index refers
to a local .debug_addr or a tied file .debug_addr
so lets be cautious. */
#if 0
#if 0 /* Attempted check for index uncertain, unwise. Ignore. */
if (!dbg->de_tied_data.td_tied_object &&
index > dbg->de_filesize) {
_dwarf_error_string(dbg,error,DW_DLE_ATTR_FORM_OFFSET_BAD,
@ -1275,12 +1309,15 @@ dwarf_formaddr(Dwarf_Attribute attr,
error);
return res;
}
if (attrform == DW_FORM_addr
/* || attrform == DW_FORM_ref_addr Allowance of
if (attrform == DW_FORM_addr ||
(cu_context->cc_producer == CC_PROD_METROWERKS &&
attrform == DW_FORM_ref_addr)
/* Allowance of
DW_FORM_ref_addr was a mistake. The value returned in that
case is NOT an address it is a global debug_info
offset (ie, not CU-relative offset within the CU
in debug_info).
A Metrowerks old C generates ref_adder!
The DWARF2 document refers to it as an address
(misleadingly) in sec 6.5.4 where it describes
the reference form. It is

View File

@ -77,7 +77,7 @@
#define MIN(a,b) (((a) < (b))? (a):(b))
#if 0 /* FOR DEBUGGING */
#if 0 /* dump_bytes FOR DEBUGGING */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{
@ -96,7 +96,7 @@ static void dump_frame_rule(char *msg,
static int _dwarf_initialize_fde_table(Dwarf_Debug dbg,
struct Dwarf_Frame_s *fde_table,
unsigned table_real_data_size,
Dwarf_Unsigned table_real_data_size,
Dwarf_Error * error);
static void _dwarf_free_fde_table(struct Dwarf_Frame_s *fde_table);
static void _dwarf_init_reg_rules_ru(
@ -302,7 +302,7 @@ _dwarf_free_dfi_list(Dwarf_Frame_Instr fr)
free(cur);
}
}
#if 0
#if 0 /* printlist() for debugging */
static void
printlist(Dwarf_Frame_Instr x)
{
@ -474,7 +474,8 @@ _dwarf_exec_frame_instr(Dwarf_Bool make_instr,
SER(DW_DLE_FRAME_REGISTER_COUNT_MISMATCH);
}
minregcount =
MIN(reg_count,cie->ci_initial_table->fr_reg_count);
(unsigned)MIN(reg_count,
cie->ci_initial_table->fr_reg_count);
for ( ; curreg < minregcount ;
curreg++, t1reg++, t2reg++) {
*t1reg = *t2reg;
@ -1811,7 +1812,7 @@ _dwarf_exec_frame_instr(Dwarf_Bool make_instr,
struct Dwarf_Reg_Rule_s *t2reg = table->fr_reg;
struct Dwarf_Reg_Rule_s *t3reg = localregtab;
unsigned minregcount = MIN(table->fr_reg_count,reg_count);
unsigned minregcount = (unsigned)MIN(table->fr_reg_count,reg_count);
unsigned curreg = 0;
table->fr_loc = current_loc;
@ -2161,9 +2162,9 @@ dwarf_get_fde_for_die(Dwarf_Debug dbg,
return DW_DLV_ERROR;
}
cie_ptr = new_fde->fd_section_ptr + cie_id;
if ((Dwarf_Unsigned)cie_ptr <
(Dwarf_Unsigned) new_fde->fd_section_ptr ||
(Dwarf_Unsigned)cie_ptr < cie_id) {
if ((Dwarf_Unsigned)(uintptr_t)cie_ptr <
(Dwarf_Unsigned)(uintptr_t)new_fde->fd_section_ptr ||
(Dwarf_Unsigned)(uintptr_t)cie_ptr < cie_id) {
dwarf_dealloc(dbg,new_fde,DW_DLA_FDE);
new_fde = 0;
_dwarf_error_string(dbg, error, DW_DLE_NO_CIE_FOR_FDE,
@ -2333,7 +2334,8 @@ dwarf_get_cie_info_b(Dwarf_Cie cie,
if (data_alignment_factor != NULL)
*data_alignment_factor = cie->ci_data_alignment_factor;
if (return_address_register != NULL)
*return_address_register = cie->ci_return_address_register;
*return_address_register =
(Dwarf_Half)cie->ci_return_address_register;
if (initial_instructions != NULL)
*initial_instructions = cie->ci_cie_instr_start;
if (initial_instructions_length != NULL) {
@ -2554,7 +2556,7 @@ dwarf_get_fde_info_for_all_regs3_b(Dwarf_Fde fde,
reg_table->rt3_cfa_rule.dw_value_type =
fde_table.fr_cfa_rule.ru_value_type;
reg_table->rt3_cfa_rule.dw_regnum =
fde_table.fr_cfa_rule.ru_register;
(Dwarf_Half)fde_table.fr_cfa_rule.ru_register;
reg_table->rt3_cfa_rule.dw_offset =
(Dwarf_Unsigned)fde_table.fr_cfa_rule.ru_offset;
reg_table->rt3_cfa_rule.dw_block =
@ -2778,7 +2780,7 @@ dwarf_get_fde_info_for_cfa_reg3_c(Dwarf_Fde fde,
int res = DW_DLV_ERROR;
Dwarf_Debug dbg = 0;
int table_real_data_size = 0;
Dwarf_Unsigned table_real_data_size = 0;
FDE_NULL_CHECKS_AND_SET_DBG(fde, dbg);
@ -3236,7 +3238,7 @@ dwarf_get_fde_augmentation_data(Dwarf_Fde fde,
return DW_DLV_OK;
}
#if 0 /* FOR DEBUGGING */
#if 0 /* dump_frame_rule() FOR DEBUGGING */
/* Used solely for debugging libdwarf. */
static void
dump_frame_rule(char *msg, struct Dwarf_Reg_Rule_s *reg_rule)
@ -3276,7 +3278,8 @@ dump_frame_rule(char *msg, struct Dwarf_Reg_Rule_s *reg_rule)
Dwarf_Half
dwarf_set_frame_rule_initial_value(Dwarf_Debug dbg, Dwarf_Half value)
{
Dwarf_Unsigned orig = dbg->de_frame_rule_initial_value;
Dwarf_Half orig =
(Dwarf_Half)dbg->de_frame_rule_initial_value;
dbg->de_frame_rule_initial_value = value;
return orig;
}
@ -3295,7 +3298,8 @@ dwarf_set_frame_rule_initial_value(Dwarf_Debug dbg, Dwarf_Half value)
Dwarf_Half
dwarf_set_frame_rule_table_size(Dwarf_Debug dbg, Dwarf_Half value)
{
Dwarf_Half orig = dbg->de_frame_reg_rules_entry_count;
Dwarf_Half orig =
(Dwarf_Half)dbg->de_frame_reg_rules_entry_count;
dbg->de_frame_reg_rules_entry_count = value;
/* Take the caller-specified value, but do not
@ -3322,7 +3326,7 @@ dwarf_set_frame_rule_table_size(Dwarf_Debug dbg, Dwarf_Half value)
Dwarf_Half
dwarf_set_frame_cfa_value(Dwarf_Debug dbg, Dwarf_Half value)
{
Dwarf_Half orig = dbg->de_frame_cfa_col_number;
Dwarf_Half orig = (Dwarf_Half)dbg->de_frame_cfa_col_number;
dbg->de_frame_cfa_col_number = value;
return orig;
}
@ -3330,14 +3334,16 @@ dwarf_set_frame_cfa_value(Dwarf_Debug dbg, Dwarf_Half value)
Dwarf_Half
dwarf_set_frame_same_value(Dwarf_Debug dbg, Dwarf_Half value)
{
Dwarf_Half orig = dbg->de_frame_same_value_number;
Dwarf_Half orig =
(Dwarf_Half)dbg->de_frame_same_value_number;
dbg->de_frame_same_value_number = value;
return orig;
}
Dwarf_Half
dwarf_set_frame_undefined_value(Dwarf_Debug dbg, Dwarf_Half value)
{
Dwarf_Half orig = dbg->de_frame_same_value_number;
Dwarf_Half orig =
(Dwarf_Half)dbg->de_frame_same_value_number;
dbg->de_frame_undefined_value_number = value;
return orig;
}
@ -3357,11 +3363,11 @@ dwarf_set_default_address_size(Dwarf_Debug dbg,
static int
init_reg_rules_alloc(Dwarf_Debug dbg,struct Dwarf_Frame_s *f,
unsigned count, Dwarf_Error * error)
Dwarf_Unsigned count, Dwarf_Error * error)
{
f->fr_reg_count = count;
f->fr_reg = (struct Dwarf_Reg_Rule_s *)
calloc(sizeof(struct Dwarf_Reg_Rule_s), count);
calloc(sizeof(struct Dwarf_Reg_Rule_s), (size_t)count);
if (f->fr_reg == 0) {
if (error) {
_dwarf_error(dbg, error, DW_DLE_DF_ALLOC_FAIL);
@ -3375,7 +3381,7 @@ init_reg_rules_alloc(Dwarf_Debug dbg,struct Dwarf_Frame_s *f,
static int
_dwarf_initialize_fde_table(Dwarf_Debug dbg,
struct Dwarf_Frame_s *fde_table,
unsigned table_real_data_size,
Dwarf_Unsigned table_real_data_size,
Dwarf_Error * error)
{
unsigned entry_size = sizeof(struct Dwarf_Frame_s);
@ -3466,7 +3472,7 @@ _dwarf_init_reg_rules_ru(struct Dwarf_Reg_Rule_s *base,
Dwarf_Unsigned initial_value)
{
struct Dwarf_Reg_Rule_s *r = base+first;
unsigned i = first;
Dwarf_Unsigned i = first;
for (; i < last; ++i,++r) {
r->ru_is_offset = 0;
r->ru_value_type = DW_EXPR_OFFSET;

View File

@ -273,15 +273,15 @@ struct Dwarf_Cie_s {
char *ci_augmentation;
Dwarf_Unsigned ci_code_alignment_factor;
Dwarf_Signed ci_data_alignment_factor;
Dwarf_Small ci_return_address_register;
Dwarf_Unsigned ci_return_address_register;
Dwarf_Small *ci_cie_start;
Dwarf_Small *ci_cie_instr_start;
Dwarf_Small *ci_cie_end;
Dwarf_Debug ci_dbg;
Dwarf_Frame ci_initial_table;
Dwarf_Cie ci_next;
Dwarf_Small ci_length_size;
Dwarf_Small ci_extension_size;
Dwarf_Half ci_length_size;
Dwarf_Half ci_extension_size;
Dwarf_Half ci_cie_version_number;
enum Dwarf_augmentation_type ci_augmentation_type;
@ -489,7 +489,7 @@ int _dwarf_create_fde_from_after_start(Dwarf_Debug dbg,
Dwarf_Small *section_ptr_end,
int use_gnu_cie_calc,
Dwarf_Cie cie_ptr_in,
Dwarf_Small address_size_in,
Dwarf_Half address_size_in,
Dwarf_Fde *fde_ptr_out,
Dwarf_Error *error);

View File

@ -70,7 +70,7 @@
tables for fast access into .eh_frame.
*/
#if 0 /* FOR DEBUGGING */
#if 0 /* dump_bytes FOR DEBUGGING */
/* For debugging only. */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
@ -107,8 +107,7 @@ static int _dwarf_create_cie_from_start(Dwarf_Debug dbg,
static int _dwarf_get_gcc_eh_augmentation(Dwarf_Debug dbg,
Dwarf_Small * frame_ptr,
unsigned long
*size_of_augmentation_data,
Dwarf_Unsigned *size_of_augmentation_data,
enum Dwarf_augmentation_type augtype,
Dwarf_Small * section_end_pointer,
char *augmentation,
@ -254,7 +253,7 @@ validate_length(Dwarf_Debug dbg,
return;
}
#if 0 /* FOR DEBUGGING */
#if 0 /* print_prefix() FOR DEBUGGING */
/* For debugging only. */
static void
print_prefix(struct cie_fde_prefix_s *prefix, int line)
@ -323,7 +322,7 @@ get_cieptr_given_offset(Dwarf_Debug dbg,
cie_id itself, to
use vm ptr of the value,
less the value, to get to the cie header. */
if ((Dwarf_Unsigned)cie_id_addr <= cie_id_value) {
if ((Dwarf_Unsigned)(uintptr_t)cie_id_addr <= cie_id_value) {
_dwarf_error_string(dbg, error,
DW_DLE_DEBUG_FRAME_LENGTH_BAD,
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: in eh_frame "
@ -426,9 +425,6 @@ _dwarf_get_fde_list_internal(Dwarf_Debug dbg, Dwarf_Cie ** cie_data,
if (frame_ptr >= section_ptr_end) {
_dwarf_dealloc_fde_cie_list_internal(head_fde_ptr,
head_cie_ptr);
#if 0
_dwarf_error(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
#endif
_dwarf_error_string(dbg, error,
DW_DLE_DEBUG_FRAME_LENGTH_BAD,
"DW_DLE_DEBUG_FRAME_LENGTH_BAD: following "
@ -770,7 +766,7 @@ _dwarf_create_cie_from_after_start(Dwarf_Debug dbg,
"with the CIE incomplete. Corrupt Dwarf");
return DW_DLV_ERROR;
}
#if 0
#if 0 /* obsolete sgi exception table reference. Ignore. */
/* REFERENCED *//* Not used in this instance */
Dwarf_Unsigned exception_table_addr = 0;
/* this is per egcs-1.1.2 as on RH 6.0 */
@ -904,7 +900,7 @@ _dwarf_create_cie_from_after_start(Dwarf_Debug dbg,
case aug_eh:{
int err = 0;
unsigned long increment = 0;
Dwarf_Unsigned increment = 0;
if (!use_gnu_cie_calc) {
/* This should be impossible. */
@ -1088,7 +1084,7 @@ _dwarf_create_fde_from_after_start(Dwarf_Debug dbg,
Dwarf_Small *section_ptr_end,
int use_gnu_cie_calc,
Dwarf_Cie cie_ptr_in,
Dwarf_Small address_size,
Dwarf_Half address_size,
Dwarf_Fde *fde_ptr_out,
Dwarf_Error *error)
{
@ -1978,10 +1974,9 @@ _dwarf_get_augmentation_type(Dwarf_Debug dbg,
static int
_dwarf_get_gcc_eh_augmentation(Dwarf_Debug dbg,
Dwarf_Small * frame_ptr,
unsigned long *size_of_augmentation_data,
Dwarf_Unsigned *size_of_augmentation_data,
enum Dwarf_augmentation_type augtype,
Dwarf_Small * section_ptr_end,
char *augmentation,
Dwarf_Small * section_ptr_end, char *augmentation,
Dwarf_Error *error)
{
char *suffix = 0;

View File

@ -63,7 +63,7 @@ Index-Section-Format.html#Index-Section-Format
#if WORDS_BIGENDIAN /* meaning on this host */
#define READ_GDBINDEX(dest,desttype, source, length) \
do { \
BIGGEST_UINT _ltmp = 0; \
desttype _ltmp = 0; \
_dwarf_memcpy_swap_bytes((((char *)(&_ltmp)) \
+ sizeof(_ltmp) - (length)), \
(source), (length)) ; \
@ -72,7 +72,7 @@ Index-Section-Format.html#Index-Section-Format
#else /* little-endian on this host */
#define READ_GDBINDEX(dest,desttype, source, length) \
do { \
BIGGEST_UINT _ltmp = 0; \
desttype _ltmp = 0; \
memcpy(((char *)(&_ltmp)) , \
(source), (length)) ; \
(dest) = (desttype)_ltmp; \
@ -194,6 +194,16 @@ dwarf_gdbindex_header(Dwarf_Debug dbg,
}
}
data = dbg->de_debug_gdbindex.dss_data;
if (!data) {
/* Should be impossible, dwarf_load_section() would
return DW_DLV_ERROR if dss_data could not be
set non-null */
_dwarf_error_string(dbg, error, DW_DLE_ERRONEOUS_GDB_INDEX_SECTION,
"DW_DLE_ERRONEOUS_GDB_INDEX_SECTION: "
"We have non-zero (section) dss_size but "
"null dss_data pointer");
return DW_DLV_ERROR;
}
startdata = data;
if (dbg->de_debug_gdbindex.dss_size < (DWARF_32BIT_SIZE*6)) {

View File

@ -68,19 +68,6 @@ dwarf_init_path_dl(path true_path and globals, dbg1
#include <string.h> /* strdup() */
#include <stdio.h> /* debugging */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* close() open() */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* close() */
#endif /* _WIN32 */
#ifdef HAVE_FCNTL_H
#include <fcntl.h> /* open() O_RDONLY */
#endif /* HAVE_FCNTL_H */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -91,30 +78,6 @@ dwarf_init_path_dl(path true_path and globals, dbg1
#include "dwarf_error.h"
#include "dwarf_object_detector.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif /* O_CLOEXEC */
/* This is the initialization set intended to
handle multiple object formats.
Created September 2018
The init functions here cannot process archives.
Archives cannot be read by libdwarf.
*/
static int
open_a_file(const char * name)
{
/* Set to a file number that cannot be legal. */
int fd = -1;
fd = open(name, O_RDONLY | O_BINARY|O_CLOEXEC);
return fd;
}
static int
set_global_paths_init(Dwarf_Debug dbg, Dwarf_Error* error)
{
@ -225,12 +188,11 @@ dwarf_init_path_dl(const char *path,
return res;
}
#if 0
/* for debugging */
#if 0 /* for debugging */
static void
dump_header_fields(const char *w,Dwarf_Debug dbg)
{
printf("dadebug dumping certain fields of %s\n",w);
printf("Dumping certain fields of %s\n",w);
printf("ftype : %d\n",dbg->de_ftype);
printf("machine : %llu\n",dbg->de_obj_machine);
printf("flags : 0x%llx\n",dbg->de_obj_flags);
@ -342,11 +304,11 @@ dwarf_init_path_dl_a(const char *path,
true_path_out_buffer && *true_path_out_buffer) {
/* MacOS dSYM or GNU debuglink */
file_path = true_path_out_buffer;
fd = open_a_file(true_path_out_buffer);
fd = _dwarf_openr(true_path_out_buffer);
} else {
/* ASSERT: lpath_source = DW_PATHSOURCE_basic */
file_path = (char *)path;
fd = open_a_file(path);
fd = _dwarf_openr(path);
}
if (fd == -1) {
@ -360,7 +322,7 @@ dwarf_init_path_dl_a(const char *path,
ftype,endian,offsetsize,filesize,
groupnumber,errhand,errarg,&dbg,error);
if (res != DW_DLV_OK) {
close(fd);
_dwarf_closer(fd);
return res;
}
final_common_settings(dbg,file_path,fd,
@ -377,7 +339,7 @@ dwarf_init_path_dl_a(const char *path,
ftype,endian,offsetsize,filesize,
groupnumber,errhand,errarg,&dbg,error);
if (res != DW_DLV_OK) {
close(fd);
_dwarf_closer(fd);
return res;
}
final_common_settings(dbg,file_path,fd,
@ -392,7 +354,7 @@ dwarf_init_path_dl_a(const char *path,
ftype,endian,offsetsize,filesize,
groupnumber,errhand,errarg,&dbg,error);
if (res != DW_DLV_OK) {
close(fd);
_dwarf_closer(fd);
return res;
}
final_common_settings(dbg,file_path,fd,
@ -402,7 +364,7 @@ dwarf_init_path_dl_a(const char *path,
return res;
}
default:
close(fd);
_dwarf_closer(fd);
DWARF_DBG_ERROR(NULL, DW_DLE_FILE_WRONG_TYPE,
DW_DLV_ERROR);
/* Macro returns, cannot reach this line. */
@ -533,7 +495,7 @@ dwarf_finish(Dwarf_Debug dbg)
}
}
if (dbg->de_owns_fd) {
close(dbg->de_fd);
_dwarf_closer(dbg->de_fd);
dbg->de_owns_fd = FALSE;
}
free((void *)dbg->de_path);

View File

@ -83,7 +83,7 @@ _dwarf_fix_up_offset_irix(Dwarf_Debug dbg,
}
#endif /* __sgi */
#if 0
#if 0 /* debug_print_range (debugging) */
/* Debugging only. Requires start. can calulate one of len, end */
static void
debug_print_range(const char *msg,
@ -575,7 +575,7 @@ _dwarf_global_cu_len_error_msg(Dwarf_Debug dbg,
int errornumber,
const char * section_name,
Dwarf_Unsigned section_length,
int cu_number,
Dwarf_Unsigned cu_number,
Dwarf_Unsigned length_section_offset,
Dwarf_Unsigned length_field,
Dwarf_Error *error)
@ -1088,20 +1088,6 @@ _dwarf_internal_get_pubnames_like(Dwarf_Debug dbg,
} while (pubnames_like_ptr < section_end_ptr);
*return_count = global_count;
return DW_DLV_OK;
#if 0
if (!globals) {
return DW_DLV_OK;
}
{
int cbres = 0;
/* Cannot return DW_DLV_NO_ENTRY */
cbres = _dwarf_chain_to_array(dbg,*out_phead_chain,
global_count, globals, error);
/* head_chain no longer points to anything */
*out_phead_chain = 0;
return cbres;
}
#endif
}
static const int err3[]=
@ -1508,7 +1494,7 @@ dwarf_global_name_offsets(Dwarf_Global global,
}
/* We already checked to make sure enough room
with MIN_CU_HDR_SIZE */
#if 0
#if 0 /* Heuristic check for about to pass end, not usable. */
/* The offset had better not be too close to the end.
If it is,
_dwarf_length_of_cu_header() will step off the end and

View File

@ -57,7 +57,7 @@
#include "dwarf_gnu_index.h"
#include "dwarf_string.h"
#if 0
#if 0 /* dump_head */
static void
dump_head(const char *msg,int lno,
struct Dwarf_Gnu_Index_Head_s *h)

View File

@ -229,7 +229,7 @@ _dwarf_harmless_init(struct Dwarf_Harmless_s *dhp,unsigned size)
(char *)calloc(1,
DW_HARMLESS_ERROR_MSG_STRING_SIZE);
dhp->dh_errors[i] = newstr;
#if 0
#if 0 /* Commentary about avoiding leak */
/* BAD IDEA. just use the NULL pointer,
so we avoid problems later with
freeing. */

View File

@ -53,8 +53,10 @@
#include "dwarf_secname_ck.h"
#include "dwarf_setup_sections.h"
#if defined(HAVE_ZLIB_H) && defined(HAVE_ZSTD_H)
#ifdef HAVE_ZLIB_H
#include "zlib.h"
#endif
#ifdef HAVE_ZSTD_H
#include "zstd.h"
#endif
@ -179,7 +181,7 @@ add_relx_data_to_secdata( struct Dwarf_Section_s *secdata,
secdata->dss_is_rela = is_rela;
}
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{
@ -262,8 +264,11 @@ is_section_name_known_already(Dwarf_Debug dbg, const char *scn_name)
static int
is_a_relx_section(const char *scn_name,int type,int *is_rela)
{
if (type == SHT_RELA) {
*is_rela = TRUE;
return TRUE;
}
if (_dwarf_startswith(scn_name,".rela.")) {
*is_rela = TRUE;
return TRUE;
}
@ -271,10 +276,6 @@ is_a_relx_section(const char *scn_name,int type,int *is_rela)
*is_rela = FALSE;
return TRUE;
}
if (type == SHT_RELA) {
*is_rela = TRUE;
return TRUE;
}
if (type == SHT_REL) {
*is_rela = FALSE;
return TRUE;
@ -396,8 +397,8 @@ insert_sht_list_in_group_map(Dwarf_Debug dbg,
data = secdata.dss_data;
secend = data + secdata.dss_size;
{
unsigned i = 1;
unsigned count = doas->as_size/doas->as_entrysize;
Dwarf_Unsigned i = 1;
Dwarf_Unsigned count = doas->as_size/doas->as_entrysize;
Dwarf_Unsigned fval = 0;
/* The fields treatments with regard
@ -498,13 +499,14 @@ insert_sht_list_in_group_map(Dwarf_Debug dbg,
return resx;
}
if (!this_section_dwarf_relevant(doasx.as_name,
doasx.as_type,&is_rela) ) {
(int)doasx.as_type,&is_rela) ) {
continue;
}
data += DWARF_32BIT_SIZE;
*did_add_map = TRUE;
res = _dwarf_insert_in_group_map(dbg,
comdat_group_number,val,
(unsigned)comdat_group_number,
(unsigned)val,
doasx.as_name,
error);
if (res != DW_DLV_OK) {
@ -563,7 +565,7 @@ determine_target_group(Dwarf_Unsigned section_count,
grp = &dbg->de_groupnumbers;
grp->gd_number_of_groups = 0;
grp->gd_number_of_sections = section_count;
grp->gd_number_of_sections = (unsigned int)section_count;
if (grp->gd_map) {
_dwarf_error(dbg,error,DW_DLE_GROUP_INTERNAL_ERROR);
return DW_DLV_OK;
@ -616,7 +618,8 @@ determine_target_group(Dwarf_Unsigned section_count,
continue;
}
scn_name = doas.as_name;
if (!this_section_dwarf_relevant(scn_name,doas.as_type,
if (!this_section_dwarf_relevant(scn_name,
(int)doas.as_type,
&is_rela) ) {
continue;
}
@ -649,7 +652,8 @@ determine_target_group(Dwarf_Unsigned section_count,
groupnumber = DW_GROUPNUMBER_BASE;
}
}
if (is_a_relx_section(scn_name,doas.as_type,&is_rela)) {
if (is_a_relx_section(scn_name,(int)doas.as_type,
&is_rela)) {
continue;
}
@ -661,7 +665,8 @@ determine_target_group(Dwarf_Unsigned section_count,
}
/* !mapgroupnumber */
res = _dwarf_insert_in_group_map(dbg,
groupnumber,obj_section_index,
(unsigned)groupnumber,
(unsigned)obj_section_index,
scn_name,
error);
if (res != DW_DLV_OK) {
@ -784,7 +789,7 @@ _dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
int is_rela = FALSE;
res = _dwarf_section_get_target_group_from_map(dbg,
obj_section_index, &groupnumber,error);
(unsigned int)obj_section_index, &groupnumber,error);
if (res == DW_DLV_OK ) {
/* groupnumber is set. Fall through */
mapgroupnumber = groupnumber;
@ -817,11 +822,13 @@ _dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
groupnumber = DW_GROUPNUMBER_BASE;
}
}
if (!this_section_dwarf_relevant(scn_name,doas.as_type,
if (!this_section_dwarf_relevant(scn_name,
(int)doas.as_type,
&is_rela) ) {
continue;
}
if (!is_a_relx_section(scn_name,doas.as_type,&is_rela)
if (!is_a_relx_section(scn_name,(int)doas.as_type,
&is_rela)
&& !is_a_special_section_semi_dwarf(scn_name)) {
/* We do these actions only for group-related
sections. Do for .debug_info etc,
@ -853,10 +860,13 @@ _dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
res = is_section_name_known_already(dbg,scn_name);
if (res == DW_DLV_OK) {
#if 0 /* Removed check for section duplication */
/* DUPLICATE */
free(sections);
DWARF_DBG_ERROR(dbg, DW_DLE_SECTION_DUPLICATION,
DW_DLV_ERROR);
/* Metrowerks does this nonsense */
#endif
continue;
}
if (res == DW_DLV_ERROR) {
free(sections);
@ -901,8 +911,8 @@ _dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
is a RELA one and the 'sh_info'
refers to a debug section, add the
relocation data. */
if (is_a_relx_section(scn_name,doas.as_type,
&is_rela)) {
if (is_a_relx_section(scn_name,
(int)doas.as_type, &is_rela)) {
if ( doas.as_info < section_count) {
if (sections[doas.as_info]) {
add_relx_data_to_secdata(
@ -1069,7 +1079,7 @@ dwarf_object_init_b(Dwarf_Obj_Access_Interface_a* obj,
ASSERT: setup_result == DW_DLV_ERROR
here */
{
int myerr = 0;
Dwarf_Unsigned myerr = 0;
dwarfstring msg;
dwarfstring_constructor(&msg);
@ -1713,8 +1723,11 @@ dwarf_get_section_info_by_index_a(Dwarf_Debug dbg,
Dwarf_Unsigned *section_offset,
Dwarf_Error * error)
{
Dwarf_Unsigned sectioncount = 0;
CHECK_DBG(dbg,error,"dwarf_get_section_info_by_index_a()");
sectioncount = dwarf_get_section_count(dbg);
if (section_addr) {
*section_addr = 0;
}
@ -1730,9 +1743,11 @@ dwarf_get_section_info_by_index_a(Dwarf_Debug dbg,
if (section_offset) {
*section_offset = 0;
}
if (section_index < 0) {
return DW_DLV_NO_ENTRY;
}
/* Check if we have a valid section index */
if (section_index >= 0 && section_index <
dwarf_get_section_count(dbg)) {
if ((Dwarf_Unsigned)section_index < sectioncount){
int res = 0;
int err = 0;
struct Dwarf_Obj_Access_Section_a_s doas;
@ -1768,18 +1783,18 @@ dwarf_get_section_info_by_index_a(Dwarf_Debug dbg,
}
/* Get section count */
int
Dwarf_Unsigned
dwarf_get_section_count(Dwarf_Debug dbg)
{
struct Dwarf_Obj_Access_Interface_a_s * obj = 0;
if (IS_INVALID_DBG(dbg)) {
return DW_DLV_NO_ENTRY;
return 0;
}
obj = dbg->de_obj_file;
if (!obj) {
/* -1 */
return DW_DLV_NO_ENTRY;
return 0;
}
return obj->ai_methods->om_get_section_count(obj->ai_object);
}

View File

@ -167,7 +167,7 @@ ret_simple_full_path(Dwarf_Debug dbg,
{
char *tmp = 0;
char * mstr = 0;
unsigned long mlen = 0;
size_t mlen = 0;
dwarfstring targ;
dwarfstring nxt;
@ -181,7 +181,7 @@ ret_simple_full_path(Dwarf_Debug dbg,
mstr= dwarfstring_string(&targ);
mlen = dwarfstring_strlen(&targ) +1;
tmp = (char *) _dwarf_get_alloc(dbg, DW_DLA_STRING,
mlen);
(Dwarf_Unsigned)mlen);
if (tmp) {
_dwarf_safe_strcpy(tmp,mlen, mstr,mlen-1);
*name_ptr_out = tmp;
@ -379,9 +379,9 @@ create_fullest_file_path(Dwarf_Debug dbg,
}
{
char *mname = dwarfstring_string(&targ);
unsigned long mlen = dwarfstring_strlen(&targ)+1;
size_t mlen = dwarfstring_strlen(&targ)+1;
full_name = (char *) _dwarf_get_alloc(dbg, DW_DLA_STRING,
mlen);
(Dwarf_Unsigned)mlen);
if (!full_name) {
dwarfstring_destructor(&targ);
dwarfstring_destructor(&incdir);
@ -645,13 +645,15 @@ dwarf_srcfiles(Dwarf_Die die,
Dwarf_Signed baseindex = 0;
Dwarf_Signed file_count = 0;
Dwarf_Signed endindex = 0;
Dwarf_Signed ifp = 0;
res = dwarf_srclines_files_indexes(line_context, &baseindex,
&file_count, &endindex, error);
if (res != DW_DLV_OK) {
return res;
}
for (i = baseindex; i < endindex; ++i,fe2 = fe->fi_next ) {
for (ifp = baseindex; ifp < endindex;
++ifp,fe2 = fe->fi_next ) {
int sres = 0;
char *name_out = 0;
@ -1216,7 +1218,7 @@ dwarf_srclines_b(Dwarf_Die die,
if (linecount) {
tcount++;
}
*table_count = tcount;
*table_count = (Dwarf_Small)tcount;
return res;
}
@ -1858,7 +1860,7 @@ _dwarf_filename(Dwarf_Line_Context context,
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
#if 0
#if 0 /* erroneous correctness check. Ignore. */
if (fileno_in >= context->lc_file_entry_count) {
_dwarf_error_string(dbg,error, DW_DLE_NO_FILE_NAME,
"DW_DLE_NO_FILE_NAME "
@ -2280,7 +2282,7 @@ _dwarf_report_bad_lnct( Dwarf_Debug dbg,
char mnbuf[100];
dwarfstring_constructor_static(&f2,tnbuf,sizeof(tnbuf));
dwarf_get_LNCT_name(ltype,&typename);
dwarf_get_LNCT_name((unsigned int)ltype,&typename);
if (!typename) {
dwarfstring_append_printf_u(&f2,
"Invalid attribute "
@ -2302,8 +2304,8 @@ _dwarf_report_bad_lnct( Dwarf_Debug dbg,
static void
report_ltype_form_issue(Dwarf_Debug dbg,
int ltype,
int form,
Dwarf_Half ltype,
Dwarf_Half form,
const char *splmsg,
Dwarf_Error *error)
{
@ -2413,8 +2415,8 @@ _dwarf_decode_line_string_form(Dwarf_Debug dbg,
return DW_DLV_OK;
}
default:
report_ltype_form_issue(dbg, ltype,
form,0,error);
report_ltype_form_issue(dbg, (Dwarf_Half)ltype,
(Dwarf_Half)form,0,error);
return DW_DLV_ERROR;
}
}
@ -2516,7 +2518,7 @@ _dwarf_decode_line_udata_form(Dwarf_Debug dbg,
case DW_FORM_data8:
if (ltype != DW_LNCT_size &&
ltype != DW_LNCT_size) {
ltype != DW_LNCT_timestamp) {
break;
}
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned,
@ -2527,8 +2529,8 @@ _dwarf_decode_line_udata_form(Dwarf_Debug dbg,
return DW_DLV_OK;
default: break;
}
report_ltype_form_issue(dbg, ltype,
form,splmsg,error);
report_ltype_form_issue(dbg, (Dwarf_Half)ltype,
(Dwarf_Half)form,splmsg,error);
return DW_DLV_ERROR;
}

View File

@ -280,7 +280,7 @@ struct Dwarf_Line_Registers_s {
Dwarf_Bool lr_end_sequence; /* DWARF2 */
Dwarf_Bool lr_prologue_end; /* DWARF3 */
Dwarf_Bool lr_epilogue_begin; /* DWARF3 */
Dwarf_Small lr_isa; /* DWARF3 */
Dwarf_Half lr_isa; /* DWARF3 */
Dwarf_Unsigned lr_op_index; /* DWARF4, operation
within VLIW instruction. */
Dwarf_Unsigned lr_discriminator; /* DWARF4 */
@ -321,7 +321,7 @@ struct Dwarf_Line_s {
Dwarf_Unsigned li_line;
Dwarf_Half li_column; /*source file column number 1-N */
Dwarf_Small li_isa; /*New as of DWARF4. */
Dwarf_Half li_isa; /*New as of DWARF4. */
/* Two-level line tables.
Is index from logicals table

View File

@ -260,7 +260,7 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
if (res == DW_DLV_ERROR) {
return res;
}
version = htmp;
version = (Dwarf_Half)htmp;
line_context->lc_version_number = version;
line_ptr += DWARF_HALF_SIZE;
@ -1339,7 +1339,7 @@ read_line_table_program(Dwarf_Debug dbg,
/* This is the operand of the latest fixed_advance_pc extended
opcode. */
Dwarf_Half fixed_advance_pc = 0;
Dwarf_Unsigned fixed_advance_pc = 0;
/* Counts the number of lines in the line matrix. */
Dwarf_Unsigned line_count = 0;
@ -1513,7 +1513,8 @@ read_line_table_program(Dwarf_Debug dbg,
_dwarf_printf(dbg,dwarfstring_string(&ma));
dwarfstring_destructor(&ma);
print_line_detail(dbg,dwarfstring_string(&mb),
opcode,line_count+1, &regs,is_single_table,
(int)opcode,(unsigned)(line_count+1),
&regs,is_single_table,
is_actuals_table);
dwarfstring_destructor(&mb);
dwarfstring_destructor(&ma);
@ -1596,7 +1597,8 @@ read_line_table_program(Dwarf_Debug dbg,
#ifdef PRINTING_DETAILS
print_line_detail(dbg,"DW_LNS_copy",
opcode,line_count+1, &regs,is_single_table,
opcode,(unsigned int)line_count+1,
&regs,is_single_table,
is_actuals_table);
#endif /* PRINTING_DETAILS */
if (dolines) {
@ -1892,9 +1894,7 @@ read_line_table_program(Dwarf_Debug dbg,
case DW_LNS_fixed_advance_pc:{
Dwarf_Unsigned fpc = 0;
int apres = 0;
/*READ_UNALIGNED_CK(dbg, fixed_advance_pc,
Dwarf_Half, line_ptr,
DWARF_HALF_SIZE,error,line_ptr_end); */
apres = _dwarf_read_unaligned_ck_wrapper(dbg,
&fpc,line_ptr,DWARF_HALF_SIZE,line_ptr_end,
error);
@ -1933,7 +1933,18 @@ read_line_table_program(Dwarf_Debug dbg,
line_count);
return DW_DLV_ERROR;
}
regs.lr_address = regs.lr_address + fixed_advance_pc;
{ Dwarf_Unsigned oldad = regs.lr_address;
regs.lr_address = oldad + fixed_advance_pc;
if (regs.lr_address < oldad) {
_dwarf_error_string(dbg, error,
DW_DLE_LINE_TABLE_BAD,
"DW_DLE_LINE_TABLE_BAD: "
"DW_LNS_fixed_advance_pc "
"overflows when added to current "
"line table pc.");
return DW_DLV_ERROR;
}
}
regs.lr_op_index = 0;
#ifdef PRINTING_DETAILS
dwarfstring_constructor(&mb);
@ -1985,7 +1996,7 @@ read_line_table_program(Dwarf_Debug dbg,
return DW_DLV_ERROR;
}
regs.lr_isa = utmp2;
regs.lr_isa = (Dwarf_Half)utmp2;
#ifdef PRINTING_DETAILS
dwarfstring_constructor(&mb);
@ -2347,7 +2358,8 @@ read_line_table_program(Dwarf_Debug dbg,
#ifdef PRINTING_DETAILS
print_line_detail(dbg,
"DW_LNE_end_sequence extended",
ext_opcode, line_count+1,&regs,
(int)ext_opcode,
(unsigned int)line_count+1,&regs,
is_single_table, is_actuals_table);
#endif /* PRINTING_DETAILS */
curr_line->li_address = regs.lr_address;

View File

@ -538,7 +538,8 @@ validate_lle_value(Dwarf_Debug dbg,
dwarfstring_append_printf_s(&m,
"DW_DLE_LOCATION_ERROR: For location kind %s (",
(char *)get_loc_kind_str(locdesc->ld_kind));
(char *)get_loc_kind_str(
(Dwarf_Small)locdesc->ld_kind));
dwarfstring_append_printf_u(&m,"%u) the DW_LLE value is "
"not properly set",
locdesc->ld_kind);
@ -563,7 +564,8 @@ validate_lle_value(Dwarf_Debug dbg,
dwarfstring_constructor(&m);
dwarfstring_append_printf_s(&m,
"DW_DLE_LOCATION_ERROR: For location kind %s (",
(char *)get_loc_kind_str(locdesc->ld_kind));
(char *)get_loc_kind_str(
(Dwarf_Small)locdesc->ld_kind));
dwarfstring_append_printf_u(&m,"%u) the DW_LLEX value is "
"not properly set",
locdesc->ld_kind);
@ -590,7 +592,7 @@ _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
Dwarf_Block_c * loc_block,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small version_stamp,
Dwarf_Half version_stamp,
Dwarf_Addr lowpc,
Dwarf_Addr highpc,
Dwarf_Half lle_op,
@ -727,11 +729,11 @@ _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
break;
case DW_LKIND_GNU_exp_list:
/* DW_LKIND_GNU_exp_list */
locdesc->ld_lle_value = lle_op;
locdesc->ld_lle_value = (Dwarf_Small)lle_op;
break;
case DW_LKIND_expression:
/* This is a kind of fake, but better than 0 */
locdesc->ld_lle_value = DW_LLE_start_end;
locdesc->ld_lle_value = (Dwarf_Small)DW_LLE_start_end;
break;
case DW_LKIND_loclists:
/* ld_lle_value already set */
@ -753,7 +755,7 @@ _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
return DW_DLV_ERROR;
}
}
locdesc->ld_cents = op_count;
locdesc->ld_cents = (Dwarf_Half)op_count;
locdesc->ld_s = block_loc;
locdesc->ld_kind = lkind;
@ -1589,7 +1591,7 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
Dwarf_Loc_Head_c llhead = 0;
Dwarf_CU_Context cucontext = 0;
unsigned address_size = 0;
int cuversionstamp = 0;
Dwarf_Half cuversionstamp = 0;
Dwarf_Bool is_cu = FALSE;
Dwarf_Unsigned attrnum = 0;
Dwarf_Bool is_dwo = 0;
@ -1624,8 +1626,8 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
const char * attrname = "<unknown attribute>";
dwarfstring_constructor(&m);
dwarf_get_FORM_name(form,&formname);
dwarf_get_AT_name(attrnum,&attrname);
dwarf_get_FORM_name((unsigned int)form,&formname);
dwarf_get_AT_name((unsigned int)attrnum,&attrname);
dwarfstring_append_printf_u(&m,
"DW_DLE_LOC_EXPR_BAD: For Compilation Unit "
"version %u",cuversionstamp);
@ -1656,8 +1658,8 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
}
llhead->ll_cuversion = cuversionstamp;
llhead->ll_kind = lkind;
llhead->ll_attrnum = attrnum;
llhead->ll_attrform = form;
llhead->ll_attrnum = (Dwarf_Half)attrnum;
llhead->ll_attrform = (Dwarf_Half)form;
llhead->ll_dbg = dbg;
llhead->ll_address_size = address_size;
llhead->ll_offset_size = cucontext->cc_length_size;
@ -1736,7 +1738,7 @@ dwarf_loclist_from_expr_c(Dwarf_Debug dbg,
Dwarf_Unsigned expression_length,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small dwarf_version,
Dwarf_Half dwarf_version,
Dwarf_Loc_Head_c *loc_head,
Dwarf_Unsigned * listlen,
Dwarf_Error * error)
@ -1748,7 +1750,7 @@ dwarf_loclist_from_expr_c(Dwarf_Debug dbg,
int local_listlen = 1;
Dwarf_Addr rawlowpc = 0;
Dwarf_Addr rawhighpc = MAX_ADDR;
Dwarf_Small version_stamp = dwarf_version;
Dwarf_Half version_stamp = dwarf_version;
int res = 0;
CHECK_DBG(dbg,error,"dwarf_loclist_from_expr_c()");
@ -1865,7 +1867,7 @@ dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c loclist_head,
*debug_addr_unavailable = desc->ld_index_failed;
*loclist_expr_op_count_out = desc->ld_cents;
*locdesc_entry_out = desc;
*loclist_source_out = desc->ld_kind;
*loclist_source_out = (Dwarf_Small)desc->ld_kind;
*expression_offset_out = desc->ld_section_offset;
*locdesc_offset_out = desc->ld_locdesc_offset;
return DW_DLV_OK;

View File

@ -72,10 +72,9 @@ struct Dwarf_Loclists_Context_s {
64bit DWARF2 MIPS/IRIX: rc_extension_size is zero.
32bit DWARF: rc_extension_size is zero. */
Dwarf_Small lc_extension_size;
unsigned lc_version; /* 5 */
Dwarf_Small lc_address_size;
Dwarf_Small lc_segment_selector_size;
Dwarf_Half lc_version; /* 5 */
Dwarf_Unsigned lc_offset_entry_count;
/* offset in the section of the offset entries */
@ -110,7 +109,7 @@ struct Dwarf_Block_c_s {
Dwarf_Byte_Ptr bl_data;
/* DW_LKIND, see libdwarf.h.in */
Dwarf_Small bl_kind;
Dwarf_Half bl_kind;
/* Section (not CU) offset which 'data' comes from. */
Dwarf_Unsigned bl_section_offset;
@ -171,7 +170,7 @@ struct Dwarf_Loc_Expr_Op_s {
Adds the DW_LLE value (new in DWARF5).
This struct is opaque. Not visible to callers. */
struct Dwarf_Locdesc_c_s {
Dwarf_Small ld_kind; /* DW_LKIND */
Dwarf_Half ld_kind; /* DW_LKIND */
/* A DW_LLEX or DW_LLE value, real or synthesized */
Dwarf_Small ld_lle_value;
@ -232,15 +231,15 @@ struct Dwarf_Loc_Head_c_s {
/* Entry count of the ll_locdesc array. */
Dwarf_Unsigned ll_locdesc_count;
unsigned ll_attrnum;
unsigned ll_attrform;
unsigned ll_cuversion;
Dwarf_Half ll_attrnum;
Dwarf_Half ll_attrform;
Dwarf_Half ll_cuversion;
unsigned ll_address_size;
unsigned ll_offset_size;
/* The CU Context of this loclist or locexpr. */
Dwarf_CU_Context ll_context;
/* DW_LKIND* */
Dwarf_Small ll_kind;
Dwarf_Half ll_kind;
Dwarf_Debug ll_dbg;
unsigned long ll_magic;
@ -281,7 +280,7 @@ int _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
Dwarf_Block_c * loc_block,
Dwarf_Half address_size,
Dwarf_Half offset_size,
Dwarf_Small version_stamp,
Dwarf_Half version_stamp,
Dwarf_Addr lowpc,
Dwarf_Addr highpc,
Dwarf_Half lle_op,

View File

@ -68,7 +68,7 @@ read_encoded_addr(Dwarf_Small *loc_ptr,
Dwarf_Error *error)
{
int len = 0;
Dwarf_Small op = *loc_ptr;
Dwarf_Half op = *loc_ptr;
Dwarf_Unsigned operand = 0;
len++;
@ -654,7 +654,7 @@ _dwarf_read_loc_expr_op(Dwarf_Debug dbg,
Relocation to a different object file is up to
the user, per DWARF5 Page 41.
http://www.dwarfstd.org/ShowIssue.php?issue=100831.1 */
Dwarf_Small iplen = offset_size;
Dwarf_Half iplen = offset_size;
if (version_stamp == DW_CU_VERSION2 /* 2 */ ) {
iplen = address_size;
}

View File

@ -33,6 +33,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <config.h>
#include <stdlib.h> /* free() malloc() */
#include <stdio.h> /* printf debugging */
#include <string.h> /* memset() */
#if defined(_WIN32) && defined(HAVE_STDAFX_H)
@ -55,7 +56,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define SIZEOFT32 4
#define SIZEOFT64 8
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{
@ -120,7 +121,7 @@ read_single_lle_entry(Dwarf_Debug dbg,
Dwarf_Small *data,
Dwarf_Unsigned dataoffset,
Dwarf_Small *enddata,
unsigned address_size,
Dwarf_Half address_size,
unsigned *bytes_count_out,
unsigned *entry_kind,
Dwarf_Unsigned *entry_operand1,
@ -131,7 +132,7 @@ read_single_lle_entry(Dwarf_Debug dbg,
Dwarf_Error* error)
{
Dwarf_Unsigned count = 0;
unsigned int leblen = 0;
Dwarf_Unsigned leblen = 0;
unsigned int code = 0;
Dwarf_Unsigned val1 = 0;
Dwarf_Unsigned val2 = 0;
@ -241,7 +242,7 @@ read_single_lle_entry(Dwarf_Debug dbg,
count += address_size;
DECODE_LEB128_UWORD_LEN_CK(data,val2,leblen,
dbg,error,enddata);
count += leblen;
count += (unsigned)leblen;
res = counted_loc_descr(dbg,data,enddata,
dataoffset,
&loc_ops_overall_size,
@ -276,8 +277,19 @@ read_single_lle_entry(Dwarf_Debug dbg,
}
break;
}
*bytes_count_out = count;
*entry_kind = code;
{
unsigned int v = (unsigned int)count;
if ((Dwarf_Unsigned)v != count) {
_dwarf_error_string(dbg,error,DW_DLE_LOCLISTS_ERROR,
"DW_DLE_LOCLISTS_ERROR: "
"The number of bytes in a single "
"loclist entry is "
"too large to be reasonable");
return DW_DLV_ERROR;
}
}
*bytes_count_out = (unsigned)count;
*entry_kind = (unsigned)code;
*entry_operand1 = val1;
*entry_operand2 = val2;
*opsblocksize = loc_ops_len;
@ -353,7 +365,7 @@ _dwarf_internal_read_loclists_header(Dwarf_Debug dbg,
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
buildhere->lc_version = version;
buildhere->lc_version = (Dwarf_Half)version;
data += SIZEOFT16;
READ_UNALIGNED_CK(dbg,address_size,unsigned,data,
@ -661,7 +673,7 @@ int dwarf_get_loclist_head_basics(Dwarf_Loc_Head_c head,
"dwarf_get_loclist_head_basics()");
return DW_DLV_ERROR;
}
*lkind = head->ll_kind;
*lkind = (Dwarf_Small)head->ll_kind;
*lle_count = head->ll_locdesc_count;
*lle_version = head->ll_cuversion;
*loclists_index_returned = head->ll_index;
@ -791,7 +803,7 @@ int dwarf_get_loclist_lle(Dwarf_Debug dbg,
Dwarf_Small *data = 0;
Dwarf_Small *enddata = 0;
int res = 0;
unsigned address_size = 0;
Dwarf_Half address_size = 0;
CHECK_DBG(dbg,error,"dwarf_get_loclist_lle()");
if (!dbg->de_loclists_context_count) {
@ -1215,7 +1227,7 @@ _dwarf_loclists_fill_in_lle_head(Dwarf_Debug dbg,
return DW_DLV_OK;
}
#if 0
#if 0 /* candiate??? for public api */
int
dwarf_get_loclists_entry_fields(
Dwarf_Loc_Head_c head,

View File

@ -6,7 +6,8 @@
some original comments hard to follow.
cctools-895 in its original form
is available from https://opensource.apple.com/
see Developer Tools version 8.2.1. cctools-895/include/loader.h */
see Developer Tools version 8.2.1. cctools-895/include/loader.h
and cctools-1009.3/cctools/include/mach-o/loader.h */
/*
* Copyright (c) 1999-2010 Apple Inc. All Rights Reserved.
*
@ -471,6 +472,25 @@ like environment variable */
#define LC_VERSION_MIN_WATCHOS 0x30
/* build for Watch min OS version */
#define LC_NOTE 0x31
/* arbitrary data included within a Mach-O file */
#define LC_BUILD_VERSION 0x32
/* build for platform min OS version */
#define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD)
/* used with linkedit_data_command, payload is trie */
#define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD)
/* used with linkedit_data_command */
#define LC_FILESET_ENTRY (0x35 | LC_REQ_DYLD)
/* used with fileset_entry_command */
#define LC_ATOM_INFO 0x36
/* used with linkedit_data_command */
/*
* A variable length string in a load command
* is represented by an lc_str

View File

@ -57,24 +57,10 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif /* _WIN32 */
#include <config.h>
#include <stdlib.h> /* calloc() free() malloc() */
#include <string.h> /* memcpy() memset() strcmp() strdup() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* close() */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* close() */
#endif /* _WIN32 */
#include <stdio.h> /* debugging printf */
#include "dwarf.h"
@ -92,7 +78,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dwarf_object_detector.h"
#include "dwarf_macho_loader.h"
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{
@ -131,7 +117,7 @@ static int
_dwarf_object_detector_universal_head_fd(
int fd,
Dwarf_Unsigned dw_filesize,
unsigned int *dw_contentcount,
unsigned int *dw_contentcount,
Dwarf_Universal_Head * dw_head,
int *errcode);
@ -241,9 +227,9 @@ macho_load_section (void *obj, Dwarf_Unsigned section_index,
return DW_DLV_ERROR;
}
res = RRMOA(macho->mo_fd,
sp->loaded_data, (off_t)(inner+sp->offset),
(size_t)sp->size,
(off_t)(inner+macho->mo_filesize), error);
sp->loaded_data, (inner+sp->offset),
sp->size,
(inner+macho->mo_filesize), error);
if (res != DW_DLV_OK) {
free(sp->loaded_data);
sp->loaded_data = 0;
@ -262,7 +248,7 @@ _dwarf_destruct_macho_internals(
Dwarf_Unsigned i = 0;
if (mp->mo_destruct_close_fd) {
close(mp->mo_fd);
_dwarf_closer(mp->mo_fd);
mp->mo_fd = -1;
}
if (mp->mo_commands){
@ -320,7 +306,7 @@ load_macho_header32(dwarf_macho_object_access_internals_t *mfp,
return DW_DLV_ERROR;
}
res = RRMOA(mfp->mo_fd, &mh32, inner, sizeof(mh32),
(off_t)(inner+mfp->mo_filesize), errcode);
(inner+mfp->mo_filesize), errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -362,7 +348,7 @@ load_macho_header64(dwarf_macho_object_access_internals_t *mfp,
return DW_DLV_ERROR;
}
res = RRMOA(mfp->mo_fd, &mh64, inner, sizeof(mh64),
(off_t)(inner+mfp->mo_filesize), errcode);
(inner+mfp->mo_filesize), errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -428,8 +414,8 @@ load_segment_command_content32(
*errcode = DW_DLE_MACH_O_SEGOFFSET_BAD;
return DW_DLV_ERROR;
}
res = RRMOA(mfp->mo_fd, &sc, (off_t)(inner+segoffset),
sizeof(sc), (off_t)(inner+filesize), errcode);
res = RRMOA(mfp->mo_fd, &sc, (inner+segoffset),
sizeof(sc), (inner+filesize), errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -487,7 +473,7 @@ load_segment_command_content64(
return DW_DLV_ERROR;
}
res = RRMOA(mfp->mo_fd,&sc,inner+segoffset,
sizeof(sc), (off_t)(inner+filesize), errcode);
sizeof(sc), inner+filesize, errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -616,8 +602,8 @@ _dwarf_macho_load_dwarf_section_details32(
return DW_DLV_ERROR;
}
res = RRMOA(mfp->mo_fd, &mosec,
(off_t)(inner+curoff), sizeof(mosec),
(off_t)(inner+mfp->mo_filesize), errcode);
inner+curoff, sizeof(mosec),
inner+mfp->mo_filesize, errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -698,8 +684,8 @@ _dwarf_macho_load_dwarf_section_details64(
}
res = RRMOA(mfp->mo_fd, &mosec,
(off_t)(inner+curoff), sizeof(mosec),
(off_t)(inner+mfp->mo_filesize), errcode);
inner+curoff, sizeof(mosec),
inner+mfp->mo_filesize, errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -757,16 +743,34 @@ _dwarf_macho_load_dwarf_sections(
dwarf_macho_object_access_internals_t *mfp,int *errcode)
{
Dwarf_Unsigned segi = 0;
Dwarf_Unsigned ftype = mfp->mo_header.filetype;
struct generic_macho_segment_command *segp =
mfp->mo_segment_commands;
if (ftype != MH_DSYM &&
ftype != MH_OBJECT) {
/* We do not think it can have DWARF */
return DW_DLV_OK;
}
for ( ; segi < mfp->mo_segment_count; ++segi,++segp) {
int res = 0;
if (strcmp(segp->segname,"__DWARF")) {
switch (ftype) {
case MH_DSYM: {
if (strcmp(segp->segname,"__DWARF")) {
/* No DWARF in this segment */
continue;
}
}
/* will have DWARF */
break;
case MH_OBJECT:
/* Likely has DWARF */
break;
default:
/* We do not think it can have DWARF */
continue;
}
/* Found DWARF, for now assume only one such. */
res = _dwarf_macho_load_dwarf_section_details(mfp,
segp,segi,errcode);
return res;
@ -809,8 +813,8 @@ _dwarf_load_macho_commands(
mcp = mfp->mo_commands;
for ( ; cmdi < mfp->mo_header.ncmds; ++cmdi,++mcp ) {
res = RRMOA(mfp->mo_fd, &mc,
(off_t)(inner+curoff), sizeof(mc),
(off_t)(inner+mfp->mo_filesize), errcode);
inner+curoff, sizeof(mc),
inner+mfp->mo_filesize, errcode);
if (res != DW_DLV_OK) {
free(mfp->mo_commands);
mfp->mo_commands = 0;
@ -1000,7 +1004,7 @@ _dwarf_macho_object_access_internals_init(
unsigned int offsetsizei = offsetsize;
Dwarf_Unsigned filesizei = filesize;
Dwarf_Unsigned fileoffseti = 0;
unsigned int unibinarycounti = 0;
unsigned int unibinarycounti = 0;
if (ftype == DW_FTYPE_APPLEUNIVERSAL) {
res = _dwarf_macho_inner_object_fd(fd,
@ -1227,8 +1231,8 @@ static const struct fat_header fhzero;
static int
_dwarf_object_detector_universal_head_fd(
int fd,
Dwarf_Unsigned dw_filesize,
unsigned int *dw_contentcount,
Dwarf_Unsigned dw_filesize,
unsigned int *dw_contentcount,
Dwarf_Universal_Head * dw_head,
int *errcode)
{
@ -1375,13 +1379,13 @@ _dwarf_object_detector_universal_head_fd(
return res;
}
memcpy(duhdp,&duhd,sizeof(duhd));
*dw_contentcount = duhd.au_count;
*dw_contentcount = (unsigned int)duhd.au_count;
duhdp->au_arches = duhd.au_arches;
*dw_head = duhdp;
return DW_DLV_OK;
}
#if 0
#if 0 /* print_arch_item debugging */
static void
print_arch_item(unsigned int i,
struct Dwarf_Universal_Arch_s* arch)

View File

@ -296,7 +296,7 @@ dwarf_get_macro_details(Dwarf_Debug dbg,
if (res != DW_DLV_OK) {
return res;
}
slen = strlen((char *) pnext) + 1;
slen = (unsigned long)strlen((char *) pnext) + 1;
pnext += slen;
if (((Dwarf_Unsigned)(pnext - macro_base)) >=
dbg->de_debug_macinfo.dss_size) {
@ -435,8 +435,7 @@ dwarf_get_macro_details(Dwarf_Debug dbg,
dwarf_dealloc(dbg,return_data,DW_DLA_STRING);
return res;
}
slen = strlen((char *) pnext) + 1;
slen = (unsigned long)strlen((char *) pnext) + 1;
_dwarf_safe_strcpy((char *)latest_str_loc,
space_needed - space_used,
(const char *)pnext,slen-1);

View File

@ -643,7 +643,8 @@ dwarf_get_macro_defundef(Dwarf_Macro_Context macro_context,
&localstring, &lerr);
if (resup != DW_DLV_OK) {
if (resup == DW_DLV_ERROR) {
int myerrno = dwarf_errno(lerr);
Dwarf_Unsigned myerrno =
(unsigned int)dwarf_errno(lerr);
if (myerrno == DW_DLE_NO_TIED_FILE_AVAILABLE) {
*macro_string =
(char *)"<DW_FORM_str_sup-no-tied_file>";
@ -1045,7 +1046,7 @@ read_operands_table(Dwarf_Macro_Context macro_context,
dbg, error, endptr);
curformentry->mf_code = opcode_number;
curformentry->mf_formcount = formcount;
curformentry->mf_formcount = (Dwarf_Small)formcount;
cur_offset = (formcount+ macro_data) - section_base;
if (cur_offset >= section_size) {
@ -1394,8 +1395,8 @@ _dwarf_internal_macro_context_by_offset(Dwarf_Debug dbg,
macro_context->mc_macro_header = macro_header;
macro_context->mc_section_offset = macro_offset;
macro_context->mc_section_size = section_size;
macro_context->mc_version_number = version;
macro_context->mc_flags = flags;
macro_context->mc_version_number = (Dwarf_Half)version;
macro_context->mc_flags = (Dwarf_Small)flags;
macro_context->mc_dbg = dbg;
macro_context->mc_offset_size_flag =
flags& MACRO_OFFSET_SIZE_FLAG?TRUE:FALSE;
@ -1439,8 +1440,8 @@ _dwarf_internal_macro_context_by_offset(Dwarf_Debug dbg,
macro_data += optablesize;
macro_context->mc_macro_ops = macro_data;
macro_context->mc_macro_header_length =macro_data - macro_header;
macro_context->mc_macro_header_length =
(Dwarf_Half)(macro_data - macro_header);
build_ops_array = FALSE;
res = _dwarf_get_macro_ops_count_internal(macro_context,
build_ops_array,

View File

@ -1,5 +1,5 @@
/* Generated routines, do not edit. */
/* Generated for source version 0.9.0 */
/* Generated for source version 0.9.1 */
/* BEGIN FILE */
@ -229,9 +229,25 @@ dwarf_get_TAG_name (unsigned int val,
case DW_TAG_lo_user:
*s_out = "DW_TAG_lo_user";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x4080. DW_TAG_TI_far_type */
case DW_TAG_MIPS_loop:
*s_out = "DW_TAG_MIPS_loop";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x4081. DW_TAG_TI_near_type */
case DW_TAG_TI_assign_register:
*s_out = "DW_TAG_TI_assign_register";
return DW_DLV_OK;
case DW_TAG_TI_ioport_type:
*s_out = "DW_TAG_TI_ioport_type";
return DW_DLV_OK;
case DW_TAG_TI_restrict_type:
*s_out = "DW_TAG_TI_restrict_type";
return DW_DLV_OK;
case DW_TAG_TI_onchip_type:
*s_out = "DW_TAG_TI_onchip_type";
return DW_DLV_OK;
case DW_TAG_HP_array_descriptor:
*s_out = "DW_TAG_HP_array_descriptor";
return DW_DLV_OK;
@ -940,11 +956,15 @@ dwarf_get_AT_name (unsigned int val,
case DW_AT_HP_block_index:
*s_out = "DW_AT_HP_block_index";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x2000. DW_AT_TI_veneer */
/* Skipping alternate spelling of value
0x2000. DW_AT_lo_user */
case DW_AT_MIPS_fde:
*s_out = "DW_AT_MIPS_fde";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x2001. DW_AT_TI_symbol_name */
/* Skipping alternate spelling of value
0x2001. DW_AT_HP_unmodifiable */
/* Skipping alternate spelling of value
@ -993,15 +1013,21 @@ dwarf_get_AT_name (unsigned int val,
case DW_AT_MIPS_has_inlines:
*s_out = "DW_AT_MIPS_has_inlines";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x200b. DW_AT_TI_version */
case DW_AT_MIPS_stride_byte:
*s_out = "DW_AT_MIPS_stride_byte";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x200c. DW_AT_TI_asm */
case DW_AT_MIPS_stride_elem:
*s_out = "DW_AT_MIPS_stride_elem";
return DW_DLV_OK;
case DW_AT_MIPS_ptr_dopetype:
*s_out = "DW_AT_MIPS_ptr_dopetype";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x200e. DW_AT_TI_skeletal */
case DW_AT_MIPS_allocatable_dopetype:
*s_out = "DW_AT_MIPS_allocatable_dopetype";
return DW_DLV_OK;
@ -1013,6 +1039,8 @@ dwarf_get_AT_name (unsigned int val,
case DW_AT_MIPS_assumed_size:
*s_out = "DW_AT_MIPS_assumed_size";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x2011. DW_AT_TI_interrupt */
/* Skipping alternate spelling of value
0x2011. DW_AT_HP_proc_per_section */
case DW_AT_HP_raw_data_ptr:
@ -2300,6 +2328,15 @@ dwarf_get_IDX_name (unsigned int val,
case DW_IDX_GNU_external:
*s_out = "DW_IDX_GNU_external";
return DW_DLV_OK;
case DW_IDX_GNU_main:
*s_out = "DW_IDX_GNU_main";
return DW_DLV_OK;
case DW_IDX_GNU_language:
*s_out = "DW_IDX_GNU_language";
return DW_DLV_OK;
case DW_IDX_GNU_linkage_name:
*s_out = "DW_IDX_GNU_linkage_name";
return DW_DLV_OK;
case DW_IDX_hi_user:
*s_out = "DW_IDX_hi_user";
return DW_DLV_OK;
@ -2815,6 +2852,27 @@ dwarf_get_LANG_name (unsigned int val,
case DW_LANG_Mojo:
*s_out = "DW_LANG_Mojo";
return DW_DLV_OK;
case DW_LANG_GLSL:
*s_out = "DW_LANG_GLSL";
return DW_DLV_OK;
case DW_LANG_GLSL_ES:
*s_out = "DW_LANG_GLSL_ES";
return DW_DLV_OK;
case DW_LANG_HLSL:
*s_out = "DW_LANG_HLSL";
return DW_DLV_OK;
case DW_LANG_OpenCL_CPP:
*s_out = "DW_LANG_OpenCL_CPP";
return DW_DLV_OK;
case DW_LANG_CPP_for_OpenCL:
*s_out = "DW_LANG_CPP_for_OpenCL";
return DW_DLV_OK;
case DW_LANG_SYCL:
*s_out = "DW_LANG_SYCL";
return DW_DLV_OK;
case DW_LANG_Ruby:
*s_out = "DW_LANG_Ruby";
return DW_DLV_OK;
case DW_LANG_lo_user:
*s_out = "DW_LANG_lo_user";
return DW_DLV_OK;
@ -3365,11 +3423,15 @@ dwarf_get_CFA_name (unsigned int val,
case DW_CFA_lo_user:
*s_out = "DW_CFA_lo_user";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x1c. DW_CFA_TI_soffset_extended */
/* Skipping alternate spelling of value
0x1c. DW_CFA_low_user */
case DW_CFA_MIPS_advance_loc8:
*s_out = "DW_CFA_MIPS_advance_loc8";
return DW_DLV_OK;
/* Skipping alternate spelling of value
0x1d. DW_CFA_TI_def_cfa_soffset */
case DW_CFA_GNU_window_save:
*s_out = "DW_CFA_GNU_window_save";
return DW_DLV_OK;
@ -3826,6 +3888,24 @@ dwarf_get_ADDR_name (unsigned int val,
case DW_ADDR_none:
*s_out = "DW_ADDR_none";
return DW_DLV_OK;
case DW_ADDR_TI_PTR8:
*s_out = "DW_ADDR_TI_PTR8";
return DW_DLV_OK;
case DW_ADDR_TI_PTR16:
*s_out = "DW_ADDR_TI_PTR16";
return DW_DLV_OK;
case DW_ADDR_TI_PTR22:
*s_out = "DW_ADDR_TI_PTR22";
return DW_DLV_OK;
case DW_ADDR_TI_PTR23:
*s_out = "DW_ADDR_TI_PTR23";
return DW_DLV_OK;
case DW_ADDR_TI_PTR24:
*s_out = "DW_ADDR_TI_PTR24";
return DW_DLV_OK;
case DW_ADDR_TI_PTR32:
*s_out = "DW_ADDR_TI_PTR32";
return DW_DLV_OK;
default: break;
}
return DW_DLV_NO_ENTRY;

View File

@ -35,19 +35,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h> /* SEEK_END SEEK_SET */
#include <string.h> /* memset() strlen() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* lseek() off_t ssize_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* lseek() off_t */
#endif /* _WIN32 */
#ifdef HAVE_FCNTL_H
#include <fcntl.h> /* open() O_RDONLY */
#endif /* HAVE_FCNTL_H */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -59,17 +46,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dwarf_macho_loader.h"
#include "dwarf_string.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#ifndef O_RDONLY
#define O_RDONLY 0
#endif
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif /* O_CLOEXEC */
/* TYP, SIZEOFT32 and ASNAR
mean we can use correctly-sized arrays of char for the
struct members instead of determining a proper integer
@ -115,7 +91,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* A flag not public to users. */
static int _dwarf_global_debuglink_crc_suppress;
#if 0
#if 0 /* debugging only */
/* debugging only */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
@ -340,7 +316,7 @@ is_archive_magic(struct elf_header *h) {
Return of DW_DLV_OK it is a PE file we recognize. */
static int
is_pe_object(int fd,
unsigned long filesize,
Dwarf_Unsigned filesize,
unsigned *endian,
unsigned *offsetsize,
int *errcode)
@ -540,42 +516,40 @@ _dwarf_object_detector_fd_a(int fd,
int *errcode)
{
struct elf_header h;
size_t readlen = sizeof(h);
int res = 0;
off_t fsize = 0;
off_t lsval = 0;
ssize_t readval = 0;
Dwarf_Unsigned readlen = sizeof(h);
Dwarf_Unsigned fsize = 0;
Dwarf_Unsigned remaininglen = 0;
int res = 0;
fsize = lseek(fd,0L,SEEK_END);
if (fsize < 0) {
res = _dwarf_seekr(fd,0,SEEK_END,&fsize);
if (res != DW_DLV_OK) {
*errcode = DW_DLE_SEEK_ERROR;
return DW_DLV_ERROR;
}
if (fsize <= (off_t)readlen) {
if (fsize <= readlen) {
/* Not a real object file */
*errcode = DW_DLE_FILE_TOO_SMALL;
return DW_DLV_ERROR;
}
remaininglen = fsize - fileoffsetbase;
if ((Dwarf_Unsigned)fsize <= fileoffsetbase) {
printf("FAIL: fsize <= offsetbase impossible\n");
if (fsize <= fileoffsetbase) {
*errcode = DW_DLE_SEEK_ERROR;
return DW_DLV_ERROR;
}
remaininglen = fsize - fileoffsetbase;
if (remaininglen <= readlen) {
/* Not a real object file */
*errcode = DW_DLE_FILE_TOO_SMALL;
return DW_DLV_ERROR;
}
lsval = lseek(fd,fileoffsetbase,SEEK_SET);
if (lsval < 0) {
/* fileoffsetbase is non zero iff we have
an Apple Universal Binary. */
res = _dwarf_seekr(fd,fileoffsetbase,SEEK_SET,0);
if (res != DW_DLV_OK) {
*errcode = DW_DLE_SEEK_ERROR;
return DW_DLV_ERROR;
}
readval = read(fd,&h,readlen);
if (readval != (ssize_t)readlen) {
res = _dwarf_readr(fd,(char *)&h,readlen,0);
if (res != DW_DLV_OK) {
*errcode = DW_DLE_READ_ERROR;
return DW_DLV_ERROR;
}
@ -661,7 +635,7 @@ dwarf_object_detector_path_dSYM(
*errcode = DW_DLE_PATH_SIZE_TOO_SMALL;
return DW_DLV_ERROR;
}
fd = open(outpath,O_RDONLY|O_BINARY|O_CLOEXEC);
fd = _dwarf_openr(outpath);
if (fd < 0) {
outpath[0] = 0;
return DW_DLV_NO_ENTRY;
@ -670,10 +644,10 @@ dwarf_object_detector_path_dSYM(
res = dwarf_object_detector_fd(fd,
ftype,endian,offsetsize,filesize,errcode);
if (res != DW_DLV_OK) {
close(fd);
_dwarf_closer(fd);
return res;
}
close(fd);
_dwarf_closer(fd);
return DW_DLV_OK;
}
return DW_DLV_NO_ENTRY;
@ -920,12 +894,12 @@ _dwarf_debuglink_finder_internal(
/* First, open the file to determine if it exists.
If not, loop again */
pfd = open(pa,O_RDONLY|O_BINARY| O_CLOEXEC);
pfd = _dwarf_openr(pa);
if (pfd < 0) {
/* This is the usual path. */
continue;
}
close(pfd);
_dwarf_closer(pfd);
/* ASSERT: never returns DW_DLV_ERROR */
res = _dwarf_debuglink_finder_newpath(
pa,crc,buildid_length, buildid,
@ -984,7 +958,7 @@ dwarf_object_detector_path_b(
if (res == DW_DLV_ERROR) {
dwarfstring_destructor(&m);
if (debuglink_fd != -1) {
close(debuglink_fd);
_dwarf_closer(debuglink_fd);
}
return res;
}
@ -998,7 +972,7 @@ dwarf_object_detector_path_b(
lpathsource = DW_PATHSOURCE_basic;
} else {
if (debuglink_fd != -1) {
close(debuglink_fd);
_dwarf_closer(debuglink_fd);
debuglink_fd = -1;
}
dllenszt = dwarfstring_strlen(&m)+1;
@ -1015,11 +989,11 @@ dwarf_object_detector_path_b(
lpathsource = DW_PATHSOURCE_debuglink;
}
dwarfstring_destructor(&m);
fd = open(outpath,O_RDONLY|O_BINARY|O_CLOEXEC);
fd = _dwarf_openr(outpath);
/* fall through to get fsize etc */
} else {
lpathsource = DW_PATHSOURCE_basic;
fd = open(path,O_RDONLY|O_BINARY|O_CLOEXEC);
fd = _dwarf_openr(path);
}
if (fd < 0) {
if (pathsource) {
@ -1035,6 +1009,6 @@ dwarf_object_detector_path_b(
if (pathsource) {
*pathsource = lpathsource;
}
close(fd);
_dwarf_closer(fd);
return res;
}

View File

@ -30,24 +30,10 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif /* _WIN32 */
#include <config.h>
#include <stddef.h> /* size_t */
#include <stdio.h> /* SEEK_END SEEK_SET */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* off_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* off_t */
#endif /* _WIN32*/
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -59,14 +45,16 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Neither off_t nor ssize_t is in C90.
However, both are in Posix:
IEEE Std 1003.1-1990, aka
ISO/IEC 9954-1:1990. */
ISO/IEC 9954-1:1990.
This gets asked to read large sections sometimes.
The Linux kernel allows at most 0x7ffff000
bytes in a read()*/
int
_dwarf_object_read_random(int fd, char *buf, off_t loc,
size_t size, off_t filesize, int *errc)
_dwarf_object_read_random(int fd, char *buf, Dwarf_Unsigned loc,
Dwarf_Unsigned size, Dwarf_Unsigned filesize, int *errc)
{
off_t scode = 0;
ssize_t rcode = 0;
off_t endpoint = 0;
Dwarf_Unsigned endpoint = 0;
int res = 0;
if (loc >= filesize) {
/* Seek can seek off the end. Lets not allow that.
@ -75,22 +63,26 @@ _dwarf_object_read_random(int fd, char *buf, off_t loc,
return DW_DLV_ERROR;
}
endpoint = loc+size;
if (endpoint < loc) {
/* Overflow! The object is corrupt. */
*errc = DW_DLE_READ_OFF_END;
return DW_DLV_ERROR;
}
if (endpoint > filesize) {
/* Let us -not- try to read past end of object.
The object is corrupt. */
*errc = DW_DLE_READ_OFF_END;
return DW_DLV_ERROR;
}
scode = lseek(fd,loc,SEEK_SET);
if (scode == (off_t)-1) {
res = _dwarf_seekr(fd,loc,SEEK_SET,0);
if (res != DW_DLV_OK) {
*errc = DW_DLE_SEEK_ERROR;
return DW_DLV_ERROR;
}
rcode = read(fd,buf,size);
if (rcode == -1 ||
(size_t)rcode != size) {
*errc = DW_DLE_READ_ERROR;
return DW_DLV_ERROR;
res = _dwarf_readr(fd,buf,size,0);
if (res != DW_DLV_OK) {
*errc = DW_DLE_READ_ERROR;
return DW_DLV_ERROR;
}
return DW_DLV_OK;
}

View File

@ -37,8 +37,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern "C" {
#endif /* __cplusplus */
int _dwarf_object_read_random(int fd,char *buf,off_t loc,
size_t size,off_t filesize,int *errc);
int _dwarf_object_read_random(int fd,char *buf,Dwarf_Unsigned loc,
Dwarf_Unsigned size,Dwarf_Unsigned filesize,int *errc);
#ifdef __cplusplus
}

View File

@ -110,6 +110,8 @@ struct Dwarf_Attribute_s {
Dwarf_Attribute ar_next;
};
#define CC_PROD_METROWERKS 1
/*
This structure provides the context for a compilation unit.
Thus, it contains the Dwarf_Debug, cc_dbg, that this cu
@ -171,6 +173,9 @@ struct Dwarf_CU_Context_s {
compilation unit. */
Dwarf_Small cc_address_size;
Dwarf_Small cc_segment_selector_size;
/* Normally zero, For the defective Metrowerks
compiler is set to CC_PROD_METROW */
Dwarf_Small cc_producer;
/* cc_debug_offset is the global offset in the section
of the area length field of the CU.
@ -183,6 +188,7 @@ struct Dwarf_CU_Context_s {
See cc_is_info flag. */
Dwarf_Unsigned cc_debug_offset;
/* === START DEBUG FISSION (Split Dwarf) data
cc_signature is in the TU header
of a type unit of a TU DIE (or for DW5 in the
@ -430,7 +436,7 @@ struct Dwarf_Section_s {
const char * dss_standard_name;
/* Object section number in object file. */
unsigned dss_number;
Dwarf_Unsigned dss_number;
/* These are elf flags and non-elf object should
just leave these fields zero. */
@ -495,9 +501,9 @@ typedef struct Dwarf_Debug_InfoTypes_s *Dwarf_Debug_InfoTypes;
struct Dwarf_dbg_sect_s {
/* Debug section name must not be freed, is quoted string.
This is the name from the object file itself. */
const char *ds_name;
const char *ds_name;
/* The section number in object section numbering. */
unsigned ds_number;
Dwarf_Unsigned ds_number;
/* Debug section information, points to de_debug_*member
(or the like) of the dbg struct. */
struct Dwarf_Section_s *ds_secdata;
@ -561,6 +567,9 @@ struct Dwarf_Tied_Data_s {
dg_groupnum 1 is base
dg_groupnum 2 is dwo
dg_groupnum 3 and higher are COMDAT groups (if any).
We assume the number of groups will not exceed
event the Windows 16 bit int maximum.
*/
struct Dwarf_Group_Data_s {
/* For traditional DWARF the value is one, just one group. */
@ -822,7 +831,7 @@ struct Dwarf_Debug_s {
/* New style. takes advantage of dwarfstrings capability.
This not a public function. */
int _dwarf_printf(Dwarf_Debug dbg, const char * data);
void _dwarf_printf(Dwarf_Debug dbg, const char * data);
typedef struct Dwarf_Chain_s *Dwarf_Chain;
struct Dwarf_Chain_s {
@ -1089,6 +1098,13 @@ Dwarf_Byte_Ptr _dwarf_calculate_info_section_end_ptr(
Dwarf_Byte_Ptr _dwarf_calculate_abbrev_section_end_ptr(
Dwarf_CU_Context context);
void _dwarf_closer(int fd);
int _dwarf_readr(int fd, char *buf, Dwarf_Unsigned size,
Dwarf_Unsigned *sizeread);
int _dwarf_seekr(int fd, Dwarf_Unsigned loc, int seektype,
Dwarf_Unsigned *out_loc);
int _dwarf_openr(const char *name);
int _dwarf_formblock_internal(Dwarf_Debug dbg,
Dwarf_Attribute attr,
Dwarf_CU_Context cu_context,

View File

@ -33,25 +33,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
file appropriate to reading DWARF debugging data.
*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif /* _WIN32 */
#include <config.h>
#include <stddef.h> /* size_t */
#include <stdlib.h> /* atoi() calloc() free() malloc() */
#include <string.h> /* memset() strdup() strlen() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* close() off_t */
#elif defined HAVE_UNISTD_H
#include <unistd.h> /* close() off_t */
#endif /* _WIN32*/
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -68,7 +54,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define DOS_HEADER_LEN 64
#if 0
#if 0 /* for debugging. */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -119,23 +105,6 @@ check_valid_string(char *tab,
return DW_DLV_ERROR;
}
#if 0
#ifdef WORDS_BIGENDIAN
#define ASNAR(func,t,s) \
do { \
unsigned tbyte = sizeof(t) - sizeof(s); \
(t) = 0; \
(func)(((char *)&(t))+tbyte ,&(s)[0],sizeof(s)); \
} while (0)
#else /* LITTLE ENDIAN */
#define ASNAR(func,t,s) \
do { \
(t) = 0; \
(func)(&(t),&(s)[0],sizeof(s)); \
} while (0)
#endif /* end LITTLE- BIG-ENDIAN */
#endif /*0*/
/* Name_array is 8 byte string, or it is supposed to be
anyway. */
static int
@ -275,8 +244,8 @@ load_optional_header32(dwarf_pe_object_access_internals_t *pep,
res = _dwarf_object_read_random(pep->pe_fd,
(char *)&hdr,
(off_t)offset, sizeof(IMAGE_OPTIONAL_HEADER32_dw),
(off_t)pep->pe_filesize,
offset, sizeof(IMAGE_OPTIONAL_HEADER32_dw),
pep->pe_filesize,
errcode);
if (res != DW_DLV_OK) {
return res;
@ -314,8 +283,8 @@ load_optional_header64(dwarf_pe_object_access_internals_t *pep,
}
res = _dwarf_object_read_random(pep->pe_fd,
(char *)&hdr,
(off_t)offset, sizeof(IMAGE_OPTIONAL_HEADER64_dw),
(off_t)pep->pe_filesize,
offset, sizeof(IMAGE_OPTIONAL_HEADER64_dw),
pep->pe_filesize,
errcode);
if (res != DW_DLV_OK) {
return res;
@ -431,8 +400,8 @@ pe_load_section (void *obj, Dwarf_Unsigned section_index,
}
res = _dwarf_object_read_random(pep->pe_fd,
(char *)sp->loaded_data,
(off_t)sp->PointerToRawData, (size_t)read_length,
(off_t)pep->pe_filesize,
sp->PointerToRawData, (size_t)read_length,
pep->pe_filesize,
error);
if (res != DW_DLV_OK) {
free(sp->loaded_data);
@ -463,7 +432,7 @@ _dwarf_destruct_pe_access(
}
pep = (dwarf_pe_object_access_internals_t*)(aip->ai_object);
if (pep->pe_destruct_close_fd && pep->pe_fd !=-1) {
close(pep->pe_fd);
_dwarf_closer(pep->pe_fd);
pep->pe_fd = -1;
}
free((char *)pep->pe_path);
@ -540,9 +509,9 @@ _dwarf_pe_load_dwarf_section_headers(
int irrelevant = 0;
res = _dwarf_object_read_random(pep->pe_fd,
(char *)&filesect,(off_t)cur_offset,
(char *)&filesect,cur_offset,
sizeof(filesect),
(off_t)pep->pe_filesize,
pep->pe_filesize,
errcode);
if (res != DW_DLV_OK) {
return res;
@ -556,9 +525,9 @@ _dwarf_pe_load_dwarf_section_headers(
IMAGE_SIZEOF_SHORT_NAME);
/* Have NUL terminator now. */
sec_outp->name = strdup(safe_name);
res = pe_section_name_get(pep,
safe_name,strlen(safe_name),&expname,errcode);
safe_name,(unsigned int)strlen(safe_name),
&expname,errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -655,7 +624,7 @@ _dwarf_load_pe_sections(
return DW_DLV_ERROR;
}
res = _dwarf_object_read_random(pep->pe_fd,(char *)&dhinmem,
0, sizeof(dhinmem),(off_t)pep->pe_filesize, errcode);
0, sizeof(dhinmem),pep->pe_filesize, errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -703,8 +672,8 @@ _dwarf_load_pe_sections(
res = _dwarf_object_read_random(pep->pe_fd,
(char *)&nt_sig_array[0],
(off_t)nt_address, sizeof(nt_sig_array),
(off_t)pep->pe_filesize,errcode);
nt_address, sizeof(nt_sig_array),
pep->pe_filesize,errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -726,8 +695,8 @@ _dwarf_load_pe_sections(
return DW_DLV_ERROR;
}
res = _dwarf_object_read_random(pep->pe_fd,(char *)&ifh,
(off_t)pep->pe_nt_header_offset, sizeof(ifh),
(off_t)pep->pe_filesize,errcode);
pep->pe_nt_header_offset, sizeof(ifh),
pep->pe_filesize,errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -800,9 +769,9 @@ _dwarf_load_pe_sections(
}
memset(size_field,0,sizeof(size_field));
res = _dwarf_object_read_random(pep->pe_fd,
(char *)size_field, (off_t)pep->pe_string_table_offset,
(char *)size_field, pep->pe_string_table_offset,
sizeof(size_field),
(off_t)pep->pe_filesize,errcode);
pep->pe_filesize,errcode);
if (res != DW_DLV_OK) {
return res;
}
@ -831,9 +800,9 @@ _dwarf_load_pe_sections(
}
res = _dwarf_object_read_random(pep->pe_fd,
(char *)pep->pe_string_table,
(off_t)pep->pe_string_table_offset,
pep->pe_string_table_offset,
(size_t)pep->pe_string_table_size,
(off_t)pep->pe_filesize,errcode);
pep->pe_filesize,errcode);
if (res != DW_DLV_OK) {
free(pep->pe_string_table);
pep->pe_string_table = 0;

View File

@ -25,7 +25,6 @@
Public License along with this program; if not, write the
Free Software Foundation, Inc., 51 Franklin Street - Fifth
Floor, Boston MA 02110-1301, USA.
*/
#include <config.h>
@ -236,8 +235,8 @@ print_include_directory_details(Dwarf_Debug dbg,
dwarfstring_constructor_static(&m4,locallinebuf,
sizeof(locallinebuf));
if (line_version == DW_LINE_VERSION5) {
unsigned i = 0;
unsigned dfcount =
Dwarf_Unsigned i = 0;
Dwarf_Unsigned dfcount =
line_context->lc_directory_entry_format_count;
dwarfstring_constructor(&m4);
@ -254,8 +253,8 @@ print_include_directory_details(Dwarf_Debug dbg,
valpair = line_context->lc_directory_format_values +i;
dwarfstring_append_printf_u(&m4,
" format [%2u] ",i);
res = dwarf_get_LNCT_name(valpair->up_first,
&tname);
res = dwarf_get_LNCT_name((unsigned int)
valpair->up_first, &tname);
if ( res != DW_DLV_OK) {
tname = "<unknown type>";
}
@ -264,7 +263,8 @@ print_include_directory_details(Dwarf_Debug dbg,
valpair->up_first);
dwarfstring_append_printf_s (&m4,
" %-20s\n",(char *)tname);
res = dwarf_get_FORM_name(valpair->up_second,&fname);
res = dwarf_get_FORM_name((unsigned int)
valpair->up_second,&fname);
if ( res != DW_DLV_OK) {
fname = "<unknown form>";
}
@ -448,8 +448,9 @@ print_file_entry_details(Dwarf_Debug dbg,
dwarfstring_constructor_static(&m5,locallinebuf,
sizeof(locallinebuf));
if (line_version == DW_LINE_VERSION5) {
unsigned i = 0;
unsigned dfcount = line_context->lc_file_name_format_count;
Dwarf_Unsigned i = 0;
Dwarf_Unsigned dfcount =
line_context->lc_file_name_format_count;
dwarfstring_append_printf_u(&m5,
" file entry format count %u\n",dfcount);
@ -462,7 +463,8 @@ print_file_entry_details(Dwarf_Debug dbg,
valpair = line_context->lc_file_format_values +i;
dwarfstring_append_printf_u(&m5,
" format [%2u] ",i);
res = dwarf_get_LNCT_name(valpair->up_first,&tname);
res = dwarf_get_LNCT_name((unsigned int)
valpair->up_first,&tname);
if ( res != DW_DLV_OK) {
tname = "<unknown type>";
}
@ -471,7 +473,8 @@ print_file_entry_details(Dwarf_Debug dbg,
valpair->up_first);
dwarfstring_append_printf_s(&m5,
" %-20s\n",(char *)tname);
res = dwarf_get_FORM_name(valpair->up_second,&fname);
res = dwarf_get_FORM_name((unsigned int)
valpair->up_second,&fname);
if ( res != DW_DLV_OK) {
fname = "<unknown form>";
}

View File

@ -63,7 +63,7 @@ int dwarf_get_offset_size(Dwarf_Debug dbg,
return DW_DLV_OK;
}
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -461,7 +461,7 @@ dwarf_attrlist(Dwarf_Die die,
_dwarf_error(dbg, error, DW_DLE_UNKNOWN_FORM);
return DW_DLV_ERROR;
}
newattr_form = attr_form;
newattr_form = (Dwarf_Half)attr_form;
if (attr_form == DW_FORM_indirect) {
Dwarf_Unsigned utmp6 = 0;
@ -515,7 +515,7 @@ dwarf_attrlist(Dwarf_Die die,
empty_local_attrlist(dbg,head_attr);
return DW_DLV_ERROR;
}
newattr_form = attr_form;
newattr_form = (Dwarf_Half)attr_form;
}
if (attr) {
@ -530,9 +530,10 @@ dwarf_attrlist(Dwarf_Die die,
" a Dwarf_Attribute record");
return DW_DLV_ERROR;
}
new_attr->ar_attribute = attr;
new_attr->ar_attribute_form_direct = attr_form;
new_attr->ar_attribute_form = newattr_form;
new_attr->ar_attribute = (Dwarf_Half)attr;
new_attr->ar_attribute_form_direct =
(Dwarf_Half)attr_form;
new_attr->ar_attribute_form = (Dwarf_Half)newattr_form;
/* Here the final address must be *inside* the
section, as we will read from there, and read
at least one byte, we think.
@ -755,7 +756,7 @@ _dwarf_get_value_ptr(Dwarf_Die die,
implicit_const = abbrev_list->abl_implicit_const[i];
}
if (curr_attr == attrnum_in) {
*attr_form = curr_attr_form;
*attr_form = (Dwarf_Half)curr_attr_form;
if (implicit_const_out) {
*implicit_const_out = implicit_const;
}
@ -1092,7 +1093,7 @@ _dwarf_look_in_local_and_tied(Dwarf_Half attr_form,
if (res2 != DW_DLV_OK) {
return res2;
}
#if 0
#if 0 /* An error check that is probably incorect. */
Dwarf_Unsigned addrtabsize = 0;
addrtabsize = dbg->de_debug_addr.dss_size;
If there is no .debug_addr the error here should
@ -1716,7 +1717,7 @@ dwarf_attr_offset(Dwarf_Die die, Dwarf_Attribute attr,
return DW_DLV_OK;
}
int
Dwarf_Unsigned
dwarf_die_abbrev_code(Dwarf_Die die)
{
return die->di_abbrev_code;

View File

@ -56,7 +56,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define SIZEOFT32 4
#define SIZEOFT64 8
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(const char *msg,Dwarf_Small * start, long len)
{
@ -69,7 +69,7 @@ dump_bytes(const char *msg,Dwarf_Small * start, long len)
printf("\n");
}
#endif /*0*/
#if 0
#if 0 /* dump_rh */
static void
dump_rh(const char *msg,
int line,
@ -130,7 +130,7 @@ read_single_rle_entry(Dwarf_Debug dbg,
Dwarf_Error* error)
{
Dwarf_Unsigned count = 0;
unsigned leblen = 0;
Dwarf_Unsigned leblen = 0;
unsigned code = 0;
Dwarf_Unsigned val1 = 0;
Dwarf_Unsigned val2 = 0;
@ -202,7 +202,7 @@ read_single_rle_entry(Dwarf_Debug dbg,
}
break;
}
*bytes_count_out = count;
*bytes_count_out = (unsigned int)count;
*entry_kind = code;
*entry_operand1 = val1;
*entry_operand2 = val2;
@ -309,7 +309,7 @@ _dwarf_internal_read_rnglists_header(Dwarf_Debug dbg,
dwarfstring_destructor(&m);
return DW_DLV_ERROR;
}
buildhere->rc_version = version;
buildhere->rc_version = (Dwarf_Half)version;
data += SIZEOFT16;
localoff += SIZEOFT16;
@ -709,9 +709,10 @@ int dwarf_get_rnglist_head_basics(
*rle_version = head->rh_version;
*rnglists_index_returned = head->rh_index;
*bytes_total_in_rle = head->rh_bytes_total;
*offset_size = head->rh_offset_size;
*address_size = head->rh_address_size;
*segment_selector_size = head->rh_segment_selector_size;
*offset_size = (Dwarf_Half)head->rh_offset_size;
*address_size = (Dwarf_Half)head->rh_address_size;
*segment_selector_size =
(Dwarf_Half)head->rh_segment_selector_size;
rngcontext = head->rh_localcontext;
if (rngcontext) {
*overall_offset_of_this_context =
@ -1056,7 +1057,7 @@ build_array_of_rle(Dwarf_Debug dbg,
Dwarf_Small * data = rctx->rh_rlepointer;
Dwarf_Unsigned dataoffset = rctx->rh_rlearea_offset;
Dwarf_Small *enddata = rctx->rh_end_data_area;
unsigned address_size = rctx->rh_address_size;
unsigned address_size = (unsigned int)rctx->rh_address_size;
Dwarf_Unsigned bytescounttotal= 0;
Dwarf_Unsigned latestbaseaddr = 0;
Dwarf_Bool foundbaseaddr = FALSE;

View File

@ -35,10 +35,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h> /* memset() */
#include <stdio.h> /* memset(), printf */
#if defined(_WIN32) && defined(HAVE_STDAFX_H)
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
@ -132,7 +128,7 @@ _dwarf_uint64_mult(Dwarf_Unsigned x, Dwarf_Unsigned y,
return DW_DLV_OK;
}
#if 0
#if 0 /* ignoring add check here */
/* See:
https://stackoverflow.com/questions/3944505/
detecting-signed-overflow-in-c-c

195
src/lib/libdwarf/dwarf_seekr.c vendored Normal file
View File

@ -0,0 +1,195 @@
/*
Copyright (c) 2018-2024, David Anderson All rights reserved.
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <config.h>
#include <stdlib.h> /* free() */
#include <stdio.h> /* SEEK_END SEEK_SET */
#include <string.h> /* memset() strlen() */
#ifdef _WIN32
#ifdef HAVE_STDAFX_H
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#include <io.h> /* lseek() off_t ssize_t */
#endif /* _WIN32 */
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* close() */
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_FCNTL_H
#include <fcntl.h> /* open() O_RDONLY */
#endif /* HAVE_FCNTL_H */
#ifdef _WIN64
#define lseek _lseeki64
#endif /* _WIN64 */
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* lseek() off_t */
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_FCNTL_H
#include <fcntl.h> /* open() O_RDONLY */
#endif /* HAVE_FCNTL_H */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
#include "dwarf_base_types.h"
#include "dwarf_opaque.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#ifndef O_RDONLY
#define O_RDONLY 0
#endif /* O_RDONLY */
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif /* O_CLOEXEC */
#if 0 /* debugging only */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
Dwarf_Small *end = start + len;
Dwarf_Small *cur = start;
printf("%s ",msg);
for (; cur < end; cur++) {
printf("%02x ", *cur);
}
printf("\n");
}
#endif
int
_dwarf_readr(int fd,
char *buf,
Dwarf_Unsigned size,
Dwarf_Unsigned *sizeread_out)
{
Dwarf_Signed rcode = 0;
#ifdef _WIN64
Dwarf_Unsigned max_single_read = 0x1ffff000;
#elif defined(_WIN32)
Dwarf_Unsigned max_single_read = 0xffff;
#else
Dwarf_Unsigned max_single_read = 0x1ffff000;
#endif
Dwarf_Unsigned remaining_bytes = 0;
Dwarf_Unsigned totalsize = size;
remaining_bytes = size;
while(remaining_bytes > 0) {
if (remaining_bytes > max_single_read) {
size = max_single_read;
}
#ifdef _WIN64
rcode = (Dwarf_Signed)_read(fd,buf,(unsigned const)size);
#elif defined(_WIN32)
rcode = (Dwarf_Signed)_read(fd,buf,(unsigned const)size);
#else /* linux */
rcode = (Dwarf_Signed)read(fd,buf,(size_t)size);
#endif
if (rcode < 0 || rcode != (Dwarf_Signed)size) {
return DW_DLV_ERROR;
}
remaining_bytes -= size;
buf += size;
size = remaining_bytes;
}
if (sizeread_out) {
*sizeread_out = totalsize;
}
return DW_DLV_OK;
}
int
_dwarf_seekr(int fd,
Dwarf_Unsigned loc,
int seektype,
Dwarf_Unsigned *out_loc)
{
Dwarf_Signed fsize = 0;
Dwarf_Signed sloc = 0;
sloc = (Dwarf_Signed)loc;
if (sloc < 0) {
return DW_DLV_ERROR;
}
#ifdef _WIN64
fsize = (Dwarf_Signed)lseek(fd,(__int64)loc,seektype);
#elif defined(_WIN32)
fsize = (Dwarf_Signed)lseek(fd,(off_t)loc,seektype);
#else /* linux */
fsize = (Dwarf_Signed)lseek(fd,(off_t)loc,seektype);
#endif
if (fsize < 0) {
return DW_DLV_ERROR;
}
if (out_loc) {
*out_loc = (Dwarf_Unsigned)fsize;
}
return DW_DLV_OK;
}
void
_dwarf_closer( int fd)
{
#ifdef _WIN64
_close(fd);
#elif defined(_WIN32)
_close(fd);
#else /* linux */
close(fd);
#endif
}
int
_dwarf_openr( const char *name)
{
int fd = -1;
#ifdef _WIN64
fd = _open(name, O_RDONLY | O_BINARY|O_CLOEXEC);
#elif defined(_WIN32)
fd = _open(name, O_RDONLY | O_BINARY|O_CLOEXEC);
#else /* linux */
fd = open(name, O_RDONLY | O_BINARY|O_CLOEXEC);
#endif
return fd;
}

View File

@ -44,13 +44,6 @@
#include "libdwarf_private.h"
#include "dwarf_base_types.h"
#include "dwarf_opaque.h"
#if 0
#include "dwarf_alloc.h"
#include "dwarf_error.h"
#include "dwarf_util.h"
#include "dwarf_memcpy_swap.h"
#include "dwarf_harmless.h"
#endif /* 0 */
#include "dwarf_string.h"
#include "dwarf_secname_ck.h"
#include "dwarf_setup_sections.h"
@ -137,7 +130,7 @@ set_up_section(Dwarf_Debug dbg,
name we care about as possibly compressed, which
is to say bigger than any standard section name. */
#define SECNAMEMAX 30
int secnamelen = strlen(secname);
size_t secnamelen = strlen(secname);
/* static const char *dprefix = ".debug_"; */
#define DPREFIXLEN 7
static const char *zprefix = ".zdebug_";
@ -171,7 +164,9 @@ set_up_section(Dwarf_Debug dbg,
error: 'strcmp' reading 1 or more bytes
from a region of size 0 [-Werror=stringop-overread]
So we add -Wnostringop-overread to the build as the error is
a false positive. */
a false positive. We had to drop stringop-overread
references in compiler options, such turned off
valuable warnings. */
if (postzprefix &&
!strcmp(postzprefix,targname+DPREFIXLEN)) {
/* zprefix version matches the object section

View File

@ -65,7 +65,7 @@
return DW_DLV_ERROR; \
}
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -366,8 +366,8 @@ _dwarf_trial_read_dwarf_five_hdr(Dwarf_Debug dbg,
*table_local_offset_of_array = array_local_offset;
*total_table_length = tab_length;
*length_out = length;
*local_offset_size_out = local_offset_size;
*local_extension_size_out = local_extension_size;
*local_offset_size_out = (Dwarf_Half)local_offset_size;
*local_extension_size_out = (Dwarf_Half)local_extension_size;
*version_out = version;
*padding_out = padding;
return DW_DLV_OK;

View File

@ -74,6 +74,7 @@ dwarfstring_resize_to(struct dwarfstring_s *g,size_t newlen)
size_t lastpos = g->s_size - g->s_avail;
size_t malloclen = newlen+1;
/* ASSERT: malloclen > g->s_size at both call points */
if (malloclen < minimumnewlen) {
malloclen = minimumnewlen;
}
@ -625,7 +626,7 @@ int dwarfstring_append_printf_i(dwarfstring *data,
return res;
}
#if 0
#if 0 /* Unused trimleadingzeros */
/* Counts hex chars. divide by two to get bytes from input
integer. */
static unsigned

View File

@ -66,7 +66,7 @@ dwarf_get_str(Dwarf_Debug dbg,
return DW_DLV_ERROR;
}
if (string == NULL) {
if (!string || !returned_str_len) {
_dwarf_error(dbg, error, DW_DLE_STRING_PTR_NULL);
return DW_DLV_ERROR;
}

View File

@ -181,11 +181,16 @@ _dwarf_loop_reading_debug_info_for_cu(
latestcontext = tieddbg->de_info_reading.de_cu_context;
if (has_signature) {
void *retval = 0;
Dwarf_Sig8 consign =
latestcontext->cc_signature;
void *entry =
_dwarf_tied_make_entry(&consign,latestcontext);
void *retval = 0;
Dwarf_Sig8 consign;
void *entry = 0;
if (!latestcontext) {
/* FAILED might be out of memory.*/
return DW_DLV_NO_ENTRY;
}
consign = latestcontext->cc_signature;
entry = _dwarf_tied_make_entry(&consign,latestcontext);
if (!entry) {
return DW_DLV_NO_ENTRY;
}

View File

@ -53,10 +53,6 @@
#include "dwarf_die_deliv.h"
#include "dwarf_string.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#define MINBUFLEN 1000
#define MORE_BYTES 0x80
@ -75,7 +71,7 @@ dwarf_package_version(void)
return PACKAGE_VERSION;
}
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -89,7 +85,7 @@ dump_bytes(char * msg,Dwarf_Small * start, long len)
printf("\n");
}
#endif /*0*/
#if 0
#if 0 /* dump_ab_list */
static void
dump_ab_list(const char *prefix,const char *msg,
unsigned long hash_num,
@ -638,7 +634,8 @@ copy_abbrev_table_to_new_table(Dwarf_Hash_Table htin,
order of the entries, effectively, but
that does not seem significant. */
if (newhash > htout->tb_highest_used_entry) {
htout->tb_highest_used_entry = newhash;
htout->tb_highest_used_entry =
(unsigned long)newhash;
}
listent->abl_next = entry_out[newhash];
entry_out[newhash] = listent;
@ -816,7 +813,8 @@ printf("debugging: initial size %u\n",HT_DEFAULT_TABLE_SIZE);
hash_num = hashable_val HT_MOD_OP
(hash_table_base->tb_table_entry_count-1);
if (hash_num > hash_table_base->tb_highest_used_entry) {
hash_table_base->tb_highest_used_entry = hash_num;
hash_table_base->tb_highest_used_entry =
(unsigned long)hash_num;
}
entry_base = hash_table_base->tb_entries;
entry_cur = entry_base[hash_num];
@ -919,12 +917,13 @@ printf("debugging: initial size %u\n",HT_DEFAULT_TABLE_SIZE);
hash_num = new_hashable_val HT_MOD_OP
(hash_table_base->tb_table_entry_count-1);
if (hash_num > hash_table_base->tb_highest_used_entry) {
hash_table_base->tb_highest_used_entry = hash_num;
hash_table_base->tb_highest_used_entry =
(unsigned long)hash_num;
}
hash_table_base->tb_total_abbrev_count++;
inner_list_entry->abl_code = abbrev_code;
inner_list_entry->abl_tag = abbrev_tag;
inner_list_entry->abl_tag = (Dwarf_Half)abbrev_tag;
inner_list_entry->abl_has_child = *(abbrev_ptr++);
inner_list_entry->abl_abbrev_ptr = abbrev_ptr;
inner_list_entry->abl_goffset = abb_goff;
@ -1349,21 +1348,19 @@ dwarf_register_printf_callback( Dwarf_Debug dbg,
}
/* No varargs required */
int
void
_dwarf_printf(Dwarf_Debug dbg,
const char * data)
{
int nlen = 0;
struct Dwarf_Printf_Callback_Info_s *bufdata =
&dbg->de_printf_callback;
dwarf_printf_callback_function_type func = bufdata->dp_fptr;
if (!func) {
return 0;
return;
}
nlen = strlen(data);
func(bufdata->dp_user_pointer,data);
return nlen;
return;
}
/* Often errs and errt point to the same Dwarf_Error,
@ -1404,9 +1401,10 @@ _dwarf_error_mv_s_to_t(Dwarf_Debug dbgs,Dwarf_Error *errs,
/* copy errs errno to errt by building
a new errt.
variable if there is one!
Move the error from dbgs to dbgt. */
mydw_errno = dwarf_errno(*errs);
Move the error from dbgs to dbgt.
Error numbers are all < 1000.
*/
mydw_errno = (int)dwarf_errno(*errs);
dwarf_dealloc(dbgs,*errs, DW_DLA_ERROR);
*errs = 0;
_dwarf_error(dbgt,errt, mydw_errno);

View File

@ -215,13 +215,12 @@ _dwarf_create_area_len_error(Dwarf_Debug dbg, Dwarf_Error *error,
for READ_UNALIGNED_CK the error code refers to host endianness.
*/
typedef Dwarf_Unsigned BIGGEST_UINT;
#ifdef WORDS_BIGENDIAN
#define READ_UNALIGNED_CK(dbg,dest,desttype, source,\
length,error,endptr) \
do { \
BIGGEST_UINT _ltmp = 0; \
length,error,endptr) \
do { \
desttype _ltmp = 0; \
Dwarf_Byte_Ptr readend = (source)+(length); \
if (readend < (source)) { \
_dwarf_error_string((dbg), (error), \
@ -238,14 +237,15 @@ typedef Dwarf_Unsigned BIGGEST_UINT;
return DW_DLV_ERROR; \
} \
(dbg)->de_copy_word( (((char *)(&_ltmp)) + \
sizeof(_ltmp) - (length)),(source), (length)) ; \
(dest) = (desttype)_ltmp; \
sizeof(_ltmp) - (length)),(source), \
(unsigned long)(length)) ; \
(dest) = _ltmp; \
} while (0)
#else /* LITTLE ENDIAN */
#define READ_UNALIGNED_CK(dbg,dest,desttype, source,\
length,error,endptr) \
do { \
BIGGEST_UINT _ltmp = 0; \
desttype _ltmp = 0; \
Dwarf_Byte_Ptr readend = (source)+(length); \
if (readend < (source)) { \
_dwarf_error_string((dbg), (error), \
@ -262,8 +262,8 @@ typedef Dwarf_Unsigned BIGGEST_UINT;
return DW_DLV_ERROR; \
} \
(dbg)->de_copy_word((char *)(&_ltmp), \
(source), (length)) ; \
(dest) = (desttype)_ltmp; \
(source), (unsigned long)(length)) ; \
(dest) = _ltmp; \
} while (0)
#endif

View File

@ -88,7 +88,7 @@
/* zerohashkey used as all-zero-bits for comparison. */
static const Dwarf_Sig8 zerohashkey;
#if 0
#if 0 /* dump_bytes */
static void
dump_bytes(char * msg,Dwarf_Small * start, long len)
{
@ -141,7 +141,7 @@ fill_in_offsets_headerline(Dwarf_Debug dbg,
dwarfstring_destructor(&s);
return DW_DLV_ERROR;
}
xuhdr->gx_section_id[i] = v;
xuhdr->gx_section_id[i] = (unsigned long)v;
}
return DW_DLV_OK;
}
@ -780,7 +780,8 @@ _dwarf_search_fission_for_offset(Dwarf_Debug dbg,
{
Dwarf_Unsigned i = 0;
Dwarf_Unsigned m = 0;
int secnum_index = -1; /* N index */
Dwarf_Unsigned secnum_index = 0;
Dwarf_Bool found_secnum = FALSE;
int res = 0;
for ( i = 0; i< xuhdr->gx_column_count_sections; i++) {
@ -794,10 +795,11 @@ _dwarf_search_fission_for_offset(Dwarf_Debug dbg,
}
if (num == dfp_sect_num) {
secnum_index = i;
found_secnum = TRUE;
break;
}
}
if (secnum_index == -1) {
if (FALSE == found_secnum) {
_dwarf_error(dbg,error,DW_DLE_FISSION_SECNUM_ERR);
return DW_DLV_ERROR;
}
@ -864,12 +866,14 @@ transform_xu_to_dfp(Dwarf_Xu_Index_Header xuhdr,
Dwarf_Debug_Fission_Per_CU * percu_out,
Dwarf_Error *error)
{
unsigned i = 0;
unsigned l = 0;
unsigned n = 1;
unsigned max_cols = xuhdr->gx_column_count_sections; /* L */
unsigned secnums[DW_FISSION_SECT_COUNT];
int res;
Dwarf_Unsigned i = 0;
Dwarf_Unsigned l = 0;
Dwarf_Unsigned n = 1;
Dwarf_Unsigned max_cols =
xuhdr->gx_column_count_sections;/* L */
Dwarf_Unsigned secnums[DW_FISSION_SECT_COUNT];
int res = 0;
for ( i = 0; i< max_cols; i++) {
/* We could put the secnums array into xuhdr
if recreating it is too slow. */
@ -885,7 +889,7 @@ transform_xu_to_dfp(Dwarf_Xu_Index_Header xuhdr,
for (l = 0; l < max_cols; ++l) { /* L */
Dwarf_Unsigned sec_off = 0;
Dwarf_Unsigned sec_size = 0;
unsigned l_as_sect = secnums[l];
Dwarf_Unsigned l_as_sect = secnums[l];
res = dwarf_get_xu_section_offset(xuhdr,n,l,
&sec_off,&sec_size,error);
if (res != DW_DLV_OK) {

View File

@ -99,10 +99,10 @@ extern "C" {
*/
/* Semantic Version identity for this libdwarf.h */
#define DW_LIBDWARF_VERSION "0.9.0"
#define DW_LIBDWARF_VERSION "0.9.2"
#define DW_LIBDWARF_VERSION_MAJOR 0
#define DW_LIBDWARF_VERSION_MINOR 9
#define DW_LIBDWARF_VERSION_MICRO 0
#define DW_LIBDWARF_VERSION_MICRO 2
#define DW_PATHSOURCE_unspecified 0
#define DW_PATHSOURCE_basic 1
@ -2335,10 +2335,13 @@ DW_API int dwarf_diename(Dwarf_Die dw_die,
/*! @brief Return the DIE abbrev code
The Abbrev code for a DIE is an integer assigned
by the compiler within a particular CU.
The Abbrev code for a DIE is a non-negative
integer assigned by the compiler within a particular CU.
For .debug_names abbreviations the
situation is different.
situation is conceptually similar. The code values
are arbitrary but compilers are motivated to make
them small so the object size is as small as
possible.
Returns the abbrev code of the die. Cannot fail.
@ -2347,7 +2350,7 @@ DW_API int dwarf_diename(Dwarf_Die dw_die,
@return
The abbrev code. of the DIE.
*/
DW_API int dwarf_die_abbrev_code(Dwarf_Die dw_die);
DW_API Dwarf_Unsigned dwarf_die_abbrev_code(Dwarf_Die dw_die);
/*! @brief Return TRUE if the DIE has children
@ -4572,7 +4575,7 @@ DW_API int dwarf_loclist_from_expr_c(Dwarf_Debug dw_dbg,
Dwarf_Unsigned dw_expression_length,
Dwarf_Half dw_address_size,
Dwarf_Half dw_offset_size,
Dwarf_Small dw_dwarf_version,
Dwarf_Half dw_dwarf_version,
Dwarf_Loc_Head_c* dw_loc_head,
Dwarf_Unsigned * dw_listlen,
Dwarf_Error * dw_error);
@ -6216,20 +6219,25 @@ DW_API int dwarf_get_abbrev_entry_b(Dwarf_Abbrev dw_abbrev,
@param dw_dbg
The Dwarf_Debug whose .debug_str section we want to access.
@param dw_offset
Pass in a a string offset. Start at 0, and
Pass in a string offset. Start at 0, and
for the next call pass in dw_offset
plus dw_strlen_of_string plus 1.
@param dw_string
The caller must pass in a valid pointer to a char *.
On success returns a pointer to a string from offset
dw_offset. Never dealloc or free this string.
@param dw_strlen_of_string
The caller must pass in a valid pointer to a Dwarf_Signed.
On success returns the strlen() of the string.
@param dw_error
On error dw_error is set to point to the error details.
@return
The usual value: DW_DLV_OK etc.
If there is no such section or if dw_offset is >=
the section size it returns DW_DLV_NO_ENTRY.
If there is no such section it returns DW_DLV_NO_ENTRY.
If the dw_offset is greater than the section size,
or dw_string passed in is NULL or dw_strlen_of_string
is NULL the function returns DW_DLV_ERROR.
*/
DW_API int dwarf_get_str(Dwarf_Debug dw_dbg,
Dwarf_Off dw_offset,
@ -8160,7 +8168,13 @@ DW_API int dwarf_add_debuglink_global_path(Dwarf_Debug dw_dbg,
Caller passes pointer to array of 4 unsigned char
provided by the caller and if this returns DW_DLV_OK
that is filled in.
that array is filled in.
Callers must guarantee dw_crcbuf points
to at least 4 bytes of writable memory.
Passing in a null dw_crcbug results in an
immediate return of DW_DLV_NO_ENTRY and
the pointer is not used.
@param dw_dbg
Pass in an open dw_dbg. When you attempted
@ -8169,7 +8183,7 @@ DW_API int dwarf_add_debuglink_global_path(Dwarf_Debug dw_dbg,
The function reads the file into memory
and performs a crc calculation.
@param dw_crcbuf
Pass in a pointer to a 4 byte area to hold
Pass in a pointer to a 4 byte area to hold
the returned crc, on success the function
puts the 4 bytes there.
@param dw_error
@ -8188,6 +8202,11 @@ DW_API int dwarf_crc32(Dwarf_Debug dw_dbg,
the compiler implements unsigned int or signed int as
16 bits long.
The caller must guarantee that dw_buf is non-null
and pointing to dw_len bytes of readable memory.
If dw_buf is NULL then 0 is immediately returned
and there is no indication of error.
@param dw_buf
Pass in a pointer to some bytes on which the
crc calculation as done in debuglink is to be done.
@ -8805,6 +8824,8 @@ DW_API int dwarf_get_section_info_by_name(Dwarf_Debug dw_dbg,
@param dw_section_index
Pass in an index, 0 through N-1 where
N is the count returned from dwarf_get_section_count .
As an index type -int- works in practice, but should
really be Dwarf_Unsigned.
@param dw_section_name
On success returns a pointer to the section name
as it appears in the object file.
@ -8951,8 +8972,18 @@ DW_API int dwarf_machine_architecture(Dwarf_Debug dw_dbg,
Dwarf_Unsigned *dw_comdat_groupnumber);
/*! @brief Get section count (of object file sections).
Return the section count. Returns 0 if the
dw_debug argument is improper in any way.
@param dw_dbt
@param dw_dbg
Pass in a valid Dwarf_Debug of interest.
@return
Returns the count of sections in the object file
or zero.
*/
DW_API int dwarf_get_section_count(Dwarf_Debug dw_dbg);
DW_API Dwarf_Unsigned dwarf_get_section_count(Dwarf_Debug dw_dbg);
/*! @brief Get section sizes for many sections.

View File

@ -52,6 +52,7 @@ libdwarf_src = [
'dwarf_setup_sections.c',
'dwarf_ranges.c',
'dwarf_rnglists.c',
'dwarf_seekr.c',
'dwarf_str_offsets.c',
'dwarf_string.c',
'dwarf_stringsection.c',
@ -61,93 +62,62 @@ libdwarf_src = [
'dwarf_xu_index.c',
]
zlib_deps = dependency('zlib', method: 'pkg-config', required: false)
libzstd_deps = dependency('libzstd', method: 'pkg-config', required: false)
if dev_decompression
zlib_deps = dependency('zlib', method: 'pkg-config', required: false)
libzstd_deps = dependency('libzstd', method: 'pkg-config', required: false)
if zlib_deps.found()
message(['mesondebug found base zlib',zlib_deps.found()])
endif
if libzstd_deps.found()
message(['mesondebug found base libzstd',libzstd_deps.found()])
endif
if zlib_deps.found()
message(['mesondebug found base zlib',zlib_deps.found()])
else
if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zlib.h')
message(['mesondebug /opt/local/include/zlib.h exists'])
zlib_deps = declare_dependency(link_args: [ '-L/opt/local/lib','-lz' ],
include_directories: ['/opt/local/include'])
message(['mesondebug zlib in /opt/local',zlib_deps.found()])
endif
endif
if not zlib_deps.found()
if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zlib.h')
zlib_deps = declare_dependency(link_args: [ '-L/opt/local/lib','-lz' ],
include_directories: ['/opt/local/include'])
endif
endif
if libzstd_deps.found()
message(['mesondebug found base libzstd',libzstd_deps.found()])
else
if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zstd.h')
message(['mesondebug /opt/local/include/zstd.h exists'])
libzstd_deps = declare_dependency(link_args: ['-L/opt/local/lib','-lzstd' ],
include_directories: ['/opt/local/include'])
message(['mesondebug zstd in /opt/local', libzstd_deps.found()])
endif
endif
if zlib_deps.found()
message(['Have zlib'])
else
if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zlib.h')
message(['mesondebug /usr/local/include/zlib.h exists'])
zlib_deps = declare_dependency(link_args: [ '-L/usr/local/lib','-lz' ],
include_directories: ['/usr/local/include'])
message(['mesondebug zlib in /usr/local',zlib_deps.found()])
endif
endif
if libzstd_deps.found()
message(['Have libzstd'])
else
if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zstd.h')
message(['mesondebug /usr/local/include/zstd.h exists'])
libzstd_deps = declare_dependency(link_args: [ '-L/usr/local/lib',
'-lzstd' ],
include_directories: ['/usr/local/include'])
message(['mesondebug zstd in /usr/local',libzstd_deps.found()])
endif
endif
if zlib_deps.found()
if libzstd_deps.found()
message('mesondebug Have zlib and libzstd')
config_h.set10('HAVE_ZSTD_H',true)
config_h.set10('HAVE_ZSTD',true)
config_h.set10('HAVE_ZLIB_H',true)
config_h.set10('HAVE_ZLIB',true)
else
config_h.set10('HAVE_ZLIB_H',false)
config_h.set10('HAVE_ZLIB',false)
zlib_deps = dependency('',required: false)
if not libzstd_deps.found()
if fs.is_dir('/opt/local/lib') and fs.is_file('/opt/local/include/zstd.h')
libzstd_deps = declare_dependency(link_args: ['-L/opt/local/lib','-lzstd' ],
include_directories: ['/opt/local/include'])
endif
endif
if zlib_deps.found()
error('mesondebug libdwarf error zlib')
message(['Have zlib'])
else
if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zlib.h')
zlib_deps = declare_dependency(link_args: [ '-L/usr/local/lib','-lz' ],
include_directories: ['/usr/local/include'])
endif
endif
message('mesondebug no libzstd, set zlib_deps', zlib_deps.found())
message('mesondebug Since builds and tests both ')
message('mesondebug leaving zlib set will be ignored in build and test')
endif
else
if libzstd_deps.found()
config_h.set10('HAVE_ZSTD_H',false)
config_h.set10('HAVE_ZSTD',false)
libszstd_deps = dependency('',required: false)
if libzstd_deps.found()
error('mesondebug libdwarf error libzstd')
message(['Have libzstd'])
else
if fs.is_dir('/usr/local/lib') and fs.is_file('/usr/local/include/zstd.h')
libzstd_deps = declare_dependency(link_args: [ '-L/usr/local/lib',
'-lzstd' ],
include_directories: ['/usr/local/include'])
endif
endif
message('mesondebug no zlib, set libzstd_deps',libzstd_deps.found())
message('mesondebug Since builds and tests want both')
message('mesondebug leaving libzstd set will be ignored in build and test')
else
message('mesondebug found neither zlib nor libzstd')
endif
# Using set10 as false has the wrong effect, does not
# match what compilers expect from #ifdef in C.
if zlib_deps.found()
if libzstd_deps.found()
config_h.set10('HAVE_ZSTD_H',true)
config_h.set10('HAVE_ZSTD',true)
config_h.set10('HAVE_ZLIB_H',true)
config_h.set10('HAVE_ZLIB',true)
else
zlib_deps = dependency('',required: false)
endif
else
if libzstd_deps.found()
libszstd_deps = dependency('',required: false)
endif
endif
else
zlib_deps = dependency('',required: false)
libzstd_deps = dependency('',required: false)
endif
if (lib_type == 'shared')