From 386abd59b222b06d45f5641ae0e0be299b29123a Mon Sep 17 00:00:00 2001 From: Yahya Lmallas Date: Tue, 10 Jul 2018 14:40:34 +0100 Subject: [PATCH] Eliminate "lib*.a(filexx.cpp.o)" has no symbols on macOS (#349) * Fix compiler warning (unused variable 'ai') * Eliminate "lib*.a(filexx.cpp.o)" has no symbols on macOS On macOS there is some warnings about object that has no symbols in it, this is needed to be fixed to make building more clean and clear. example of build log : ``` [ 94%] Linking CXX static library libretdec-bin2llvmir.a /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libretdec-bin2llvmir.a(idioms_borland.cpp.o) has no symbols ``` * FIX: #331 Unify build visibility for all projects Unify build visibility for all projects to avoid warnings "direct access in function: * from file: * to global weak symbol". PS: used same function 'append_if' from LLVM Project CMakeLists.txt file This will fix #331 --- CMakeLists.txt | 22 +++++++++++++++++++ .../decoder/ir_modifications.cpp | 12 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5c5c660..f61f601d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,14 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +function(append_if condition value) + if (${condition}) + foreach(variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach(variable) + endif() +endfunction() + # On Linux and macOS, set RPATH relative to the origin of the installed # executables (i.e. relative to the bin directory). This allows us to move the # installation directory into a different location after installation, which is @@ -34,6 +42,14 @@ elseif(UNIX) set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") endif() +# Suppress superfluous randlib warnings about "*.a" having no symbols on MacOSX. +if (APPLE) + set(CMAKE_C_ARCHIVE_CREATE " Scr ") + set(CMAKE_CXX_ARCHIVE_CREATE " Scr ") + set(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") + set(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") +endif() + # Build all external projects in the same directory that is directly inside the # build directory. This reduces path lengths, which is important on Windows as # there is a limit on how long a path can be. @@ -54,6 +70,12 @@ if(MSVC) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + # Unify visibility to meet llvm's default. + include(CheckCXXCompilerFlag) + + check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) + append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS) + # Enable standard warnings. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") diff --git a/src/bin2llvmir/optimizations/decoder/ir_modifications.cpp b/src/bin2llvmir/optimizations/decoder/ir_modifications.cpp index 936f699a..b5db0f62 100644 --- a/src/bin2llvmir/optimizations/decoder/ir_modifications.cpp +++ b/src/bin2llvmir/optimizations/decoder/ir_modifications.cpp @@ -477,8 +477,16 @@ llvm::Function* Decoder::splitFunctionOn(utils::Address addr) // else if (auto ai = AsmInstruction(_module, addr)) { - LOG << "\t\t\t\t" << "S: ASM @ " << addr << std::endl; - return nullptr; + if (ai.isInvalid()) + { + LOG << "\t\t\t\t" << "S: invalid ASM @ " << addr << std::endl; + return nullptr; + } + else + { + LOG << "\t\t\t\t" << "S: ASM @ " << addr << std::endl; + return nullptr; + } } else if (getFunctionContainingAddress(addr)) {