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
This commit is contained in:
Yahya Lmallas 2018-07-10 14:40:34 +01:00 committed by Peter Matula
parent fb62ac5ef5
commit 386abd59b2
2 changed files with 32 additions and 2 deletions

View File

@ -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 "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
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")

View File

@ -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))
{