From: Rafal Krypa Date: Thu, 3 Jul 2014 12:14:53 +0000 (+0200) Subject: Remove usage of unwanted binutils library X-Git-Tag: accepted/tizen/common/20140722.142604~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=843d880197bd8e82d4adab19a8f5b0b30ce11ceb;p=platform%2Fcore%2Fsecurity%2Fcynara.git Remove usage of unwanted binutils library Change-Id: I616494d5280b87a6059149a8005911e4f7062fa3 --- diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 1d7b8c8..4b68a35 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -22,8 +22,6 @@ BuildRequires: pkgconfig(libsystemd-journal) %if %{?build_type} == "DEBUG" BuildRequires: pkgconfig(libunwind) -BuildRequires: pkgconfig(zlib) -BuildRequires: binutils-devel %endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b908c3..852e0a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,6 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") SET(COMMON_DEPS ${COMMON_DEPS} libunwind - zlib ) ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5e6308a..4962b78 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -60,9 +60,6 @@ SET_TARGET_PROPERTIES( IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") SET(CYNARA_DBG_LIBRARIES ${CYNARA_DEP_LIBRARIES} - -lbfd - -liberty - -ldl ) ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") diff --git a/src/common/log/Backtrace.cpp b/src/common/log/Backtrace.cpp index a58c0ed..26e3e02 100644 --- a/src/common/log/Backtrace.cpp +++ b/src/common/log/Backtrace.cpp @@ -22,103 +22,36 @@ * @brief Implementation of backtrace utility class. */ -#include "Backtrace.h" - #include -#include #include #include #include +#include +#include + +#include "Backtrace.h" + namespace Cynara { Backtrace &Backtrace::getInstance(void) { - static Backtrace m_instance(NULL); + static Backtrace m_instance; return m_instance; } -Backtrace::Backtrace(bfd *abfd) : - m_bfd(abfd), m_found(false), m_pc(0), m_fileName(NULL), +Backtrace::Backtrace() : + m_fileName(NULL), m_functionName(NULL), m_lineNumber(0) { } Backtrace::~Backtrace() { - if (m_bfd) { - bfd_close(m_bfd); - LOGD("Binary file closed."); - } -} - -bool Backtrace::init(void) { - char exePath[BUFSIZ]; - readlink("/proc/self/exe", exePath, BUFSIZ); - - bfd_init(); - m_bfd = bfd_openr(exePath, NULL); - if (m_bfd) { - m_bfd->flags |= BFD_DECOMPRESS; - if (bfd_check_format_matches(m_bfd, bfd_object, 0)) { - return true; - } - bfd_close(m_bfd); - m_bfd = NULL; - LOGE("Binary file check format failed."); - } else { - LOGE("Failed to open file: %s", exePath); - } - - return false; -} - -void Backtrace::findAddressInSection(bfd *abfd, asection *section, void *data) { - bfd_vma vma; - bfd_size_type size; - - Backtrace *backtrace = static_cast(data); - - if (backtrace->m_found) { - return; - } - - if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0) { - return; - } - - vma = bfd_get_section_vma(abfd, section); - if (backtrace->m_pc < vma) { - return; - } - - size = bfd_get_section_size(section); - if (backtrace->m_pc >= vma + size) { - return; - } - - backtrace->m_found = bfd_find_nearest_line(abfd, section, NULL, - backtrace->m_pc - vma, &backtrace->m_fileName, - &backtrace->m_functionName, &backtrace->m_lineNumber); } -void Backtrace::getSourceInfo(unw_word_t proc_address) { - char addr[64]; - - sprintf(addr, "0x%lx", static_cast(proc_address)); - m_pc = bfd_scan_vma(addr, NULL, 16); - m_found = false; - bfd_map_over_sections(m_bfd, findAddressInSection, this); - - if (m_found) { - while (true) { - m_found = bfd_find_inliner_info(m_bfd, &m_fileName, &m_functionName, - &m_lineNumber); - if (!m_found) - break; - } - } else { - m_fileName = "??"; - m_functionName = "??"; - m_lineNumber = 0; - } +void Backtrace::getSourceInfo(unw_word_t proc_address UNUSED) { + // TODO: extract filename and line number for symbol at given address + m_fileName = "??"; + m_functionName = "??"; + m_lineNumber = 0; } const std::string Backtrace::buildBacktrace(void) { @@ -132,10 +65,6 @@ const std::string Backtrace::buildBacktrace(void) { char *realname; int status; - if (m_bfd == NULL) { - init(); - } - unw_getcontext(&uc); // get rid of previous function: Backtrace::getBacktrace unw_init_local(&cursor, &uc); diff --git a/src/common/log/Backtrace.h b/src/common/log/Backtrace.h index 568c921..b697195 100644 --- a/src/common/log/Backtrace.h +++ b/src/common/log/Backtrace.h @@ -25,14 +25,6 @@ #ifndef SRC_COMMON_LOG_BACKTRACE_H_ #define SRC_COMMON_LOG_BACKTRACE_H_ -// Bellow two defines are needed by /usr/include/bfd.h file. -// In fact it needs config.h generated by autotools -// but we dont use autotools to build cynara so we don't have config.h -// bfd.h checks for these defines -#define PACKAGE 1 -#define PACKAGE_VERSION 1 - -#include #define UNW_LOCAL_ONLY #include #include @@ -52,21 +44,16 @@ public: private: static Backtrace &getInstance(void); - Backtrace(bfd *abfd); + Backtrace(); Backtrace(Backtrace const &) = delete; ~Backtrace(); void operator=(Backtrace const &) = delete; - bool init(void); const std::string buildBacktrace(void); - static void findAddressInSection(bfd *abfd, asection *section, void *data); void getSourceInfo(unw_word_t proc_address); private: - bfd *m_bfd; - bool m_found; - bfd_vma m_pc; const char *m_fileName; const char *m_functionName; unsigned int m_lineNumber;