From ba294bd1816aa6754836162350423238861937a7 Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Sat, 5 Oct 2024 05:49:38 +0200 Subject: [PATCH] Make sure we have a correct visibility --- api/python/CMakeLists.txt | 6 ++- cmake/LIEFOptions.cmake | 4 ++ include/LIEF/Abstract/DebugInfo.hpp | 3 +- include/LIEF/BinaryStream/BinaryStream.hpp | 6 +-- include/LIEF/BinaryStream/FileStream.hpp | 4 +- include/LIEF/BinaryStream/MemoryStream.hpp | 3 +- include/LIEF/BinaryStream/SpanStream.hpp | 4 +- include/LIEF/BinaryStream/VectorStream.hpp | 4 +- .../NoteDetails/properties/AArch64Feature.hpp | 3 +- .../ELF/NoteDetails/properties/StackSize.hpp | 3 +- .../ELF/NoteDetails/properties/X86Feature.hpp | 3 +- .../ELF/NoteDetails/properties/X86ISA.hpp | 3 +- include/LIEF/MachO/BindingInfoIterator.hpp | 3 +- include/LIEF/MachO/ChainedPointerAnalysis.hpp | 46 ++++++++++++------- include/LIEF/MachO/LoadCommand.hpp | 2 +- include/LIEF/PE/signature/PKCS9TSTInfo.hpp | 3 +- include/LIEF/range.hpp | 5 +- 17 files changed, 71 insertions(+), 34 deletions(-) diff --git a/api/python/CMakeLists.txt b/api/python/CMakeLists.txt index daa3036780..cd968a7cb6 100644 --- a/api/python/CMakeLists.txt +++ b/api/python/CMakeLists.txt @@ -1,7 +1,11 @@ find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) if (LIEF_PY_LIEF_EXT) - find_package(LIEF REQUIRED COMPONENTS STATIC) + if (LIEF_PY_LIEF_EXT_SHARED) + find_package(LIEF REQUIRED COMPONENTS SHARED) + else() + find_package(LIEF REQUIRED COMPONENTS STATIC) + endif() message(STATUS "Using pre-installed version of LIEF") set(LIEF_TARGET LIEF::LIEF) set_target_properties(LIB_LIEF PROPERTIES EXCLUDE_FROM_ALL ON) diff --git a/cmake/LIEFOptions.cmake b/cmake/LIEFOptions.cmake index d1bb81ebab..8766fc7ec0 100644 --- a/cmake/LIEFOptions.cmake +++ b/cmake/LIEFOptions.cmake @@ -37,6 +37,10 @@ option(LIEF_OBJC "Build LIEF with ObjC metadata support" OFF) cmake_dependent_option(LIEF_PYTHON_EDITABLE "Make an editable build " OFF "LIEF_PYTHON_API" OFF) +cmake_dependent_option(LIEF_PY_LIEF_EXT_SHARED + "Use a 'SHARED' version of LIEF instead of a static one" OFF + "LIEF_PY_LIEF_EXT" OFF) + cmake_dependent_option(LIEF_PYTHON_STATIC "Internal usage" OFF "LIEF_PYTHON_API" OFF) diff --git a/include/LIEF/Abstract/DebugInfo.hpp b/include/LIEF/Abstract/DebugInfo.hpp index b62ecd2ef7..43df7ef300 100644 --- a/include/LIEF/Abstract/DebugInfo.hpp +++ b/include/LIEF/Abstract/DebugInfo.hpp @@ -15,13 +15,14 @@ #ifndef LIEF_DEBUGINFO_H #define LIEF_DEBUGINFO_H #include +#include "LIEF/visibility.h" namespace LIEF { namespace details { class DebugInfo; } -class DebugInfo { +class LIEF_API DebugInfo { public: enum class FORMAT { UNKNOWN = 0, diff --git a/include/LIEF/BinaryStream/BinaryStream.hpp b/include/LIEF/BinaryStream/BinaryStream.hpp index 2120d8e3f2..db3acac7da 100644 --- a/include/LIEF/BinaryStream/BinaryStream.hpp +++ b/include/LIEF/BinaryStream/BinaryStream.hpp @@ -18,20 +18,19 @@ #include #include -#include #include #include -#include #include #include "LIEF/endianness_support.hpp" #include "LIEF/errors.hpp" +#include "LIEF/visibility.h" namespace LIEF { class ASN1Reader; //! Class that is used to a read stream of data from different sources -class BinaryStream { +class LIEF_API BinaryStream { public: friend class ASN1Reader; @@ -352,7 +351,6 @@ class ToggleEndianness { }; - template result BinaryStream::read() const { result tmp = this->peek(); diff --git a/include/LIEF/BinaryStream/FileStream.hpp b/include/LIEF/BinaryStream/FileStream.hpp index 0bb8f5bb64..0f66e95724 100644 --- a/include/LIEF/BinaryStream/FileStream.hpp +++ b/include/LIEF/BinaryStream/FileStream.hpp @@ -22,10 +22,12 @@ #include "LIEF/errors.hpp" #include "LIEF/BinaryStream/BinaryStream.hpp" +#include "LIEF/visibility.h" + namespace LIEF { //! Stream interface over a std::ifstream -class FileStream : public BinaryStream { +class LIEF_API FileStream : public BinaryStream { public: static result from_file(const std::string& file); FileStream(std::ifstream fs, uint64_t size) : diff --git a/include/LIEF/BinaryStream/MemoryStream.hpp b/include/LIEF/BinaryStream/MemoryStream.hpp index 364125f1ab..4811195ca4 100644 --- a/include/LIEF/BinaryStream/MemoryStream.hpp +++ b/include/LIEF/BinaryStream/MemoryStream.hpp @@ -19,11 +19,12 @@ #include #include "LIEF/errors.hpp" +#include "LIEF/visibility.h" #include "LIEF/BinaryStream/BinaryStream.hpp" namespace LIEF { class Binary; -class MemoryStream : public BinaryStream { +class LIEF_API MemoryStream : public BinaryStream { public: using BinaryStream::p; using BinaryStream::end; diff --git a/include/LIEF/BinaryStream/SpanStream.hpp b/include/LIEF/BinaryStream/SpanStream.hpp index 21b9b3f778..cdae83cb0c 100644 --- a/include/LIEF/BinaryStream/SpanStream.hpp +++ b/include/LIEF/BinaryStream/SpanStream.hpp @@ -20,14 +20,16 @@ #include #include #include +#include #include "LIEF/errors.hpp" #include "LIEF/span.hpp" +#include "LIEF/visibility.h" #include "LIEF/BinaryStream/BinaryStream.hpp" namespace LIEF { class VectorStream; -class SpanStream : public BinaryStream { +class LIEF_API SpanStream : public BinaryStream { public: using BinaryStream::p; using BinaryStream::end; diff --git a/include/LIEF/BinaryStream/VectorStream.hpp b/include/LIEF/BinaryStream/VectorStream.hpp index c3265745fd..f7ed16af65 100644 --- a/include/LIEF/BinaryStream/VectorStream.hpp +++ b/include/LIEF/BinaryStream/VectorStream.hpp @@ -18,13 +18,15 @@ #include #include +#include #include "LIEF/errors.hpp" +#include "LIEF/visibility.h" #include "LIEF/BinaryStream/BinaryStream.hpp" namespace LIEF { class SpanStream; -class VectorStream : public BinaryStream { +class LIEF_API VectorStream : public BinaryStream { public: using BinaryStream::p; using BinaryStream::end; diff --git a/include/LIEF/ELF/NoteDetails/properties/AArch64Feature.hpp b/include/LIEF/ELF/NoteDetails/properties/AArch64Feature.hpp index 0bc12a9513..226ec7033c 100644 --- a/include/LIEF/ELF/NoteDetails/properties/AArch64Feature.hpp +++ b/include/LIEF/ELF/NoteDetails/properties/AArch64Feature.hpp @@ -16,6 +16,7 @@ #ifndef LIEF_ELF_NOTE_DETAILS_PROPERTIES_AARCH64_FEATURE_H #define LIEF_ELF_NOTE_DETAILS_PROPERTIES_AARCH64_FEATURE_H +#include "LIEF/visibility.h" #include "LIEF/ELF/NoteDetails/NoteGnuProperty.hpp" namespace LIEF { @@ -24,7 +25,7 @@ class BinaryStream; namespace ELF { /// This class represents the `GNU_PROPERTY_AARCH64_FEATURE_1_AND` property. -class AArch64Feature : public NoteGnuProperty::Property { +class LIEF_API AArch64Feature : public NoteGnuProperty::Property { public: enum class FEATURE { UNKNOWN = 0, diff --git a/include/LIEF/ELF/NoteDetails/properties/StackSize.hpp b/include/LIEF/ELF/NoteDetails/properties/StackSize.hpp index 137bd385e3..a2e7b92632 100644 --- a/include/LIEF/ELF/NoteDetails/properties/StackSize.hpp +++ b/include/LIEF/ELF/NoteDetails/properties/StackSize.hpp @@ -17,13 +17,14 @@ #define LIEF_ELF_NOTE_DETAILS_PROPERTIES_STACK_SIZE_H #include "LIEF/ELF/NoteDetails/NoteGnuProperty.hpp" +#include "LIEF/visibility.h" namespace LIEF { namespace ELF { /// This class provides an interface over the `GNU_PROPERTY_STACK_SIZE` property /// /// This property can be used by the loader to raise the stack limit. -class StackSize : public NoteGnuProperty::Property { +class LIEF_API StackSize : public NoteGnuProperty::Property { public: static bool classof(const NoteGnuProperty::Property* prop) { return prop->type() == NoteGnuProperty::Property::TYPE::STACK_SIZE; diff --git a/include/LIEF/ELF/NoteDetails/properties/X86Feature.hpp b/include/LIEF/ELF/NoteDetails/properties/X86Feature.hpp index 5a23078fea..f2fbeb4cc7 100644 --- a/include/LIEF/ELF/NoteDetails/properties/X86Feature.hpp +++ b/include/LIEF/ELF/NoteDetails/properties/X86Feature.hpp @@ -19,6 +19,7 @@ #include #include "LIEF/ELF/NoteDetails/NoteGnuProperty.hpp" +#include "LIEF/visibility.h" namespace LIEF { namespace ELF { @@ -28,7 +29,7 @@ namespace ELF { /// - ``GNU_PROPERTY_X86_FEATURE_1_AND`` /// - ``GNU_PROPERTY_X86_FEATURE_2_USED`` /// - ``GNU_PROPERTY_X86_FEATURE_2_NEEDED`` -class X86Features : public NoteGnuProperty::Property { +class LIEF_API X86Features : public NoteGnuProperty::Property { public: /// Flag according to the ``_AND``, ``_USED`` or ``_NEEDED`` suffixes diff --git a/include/LIEF/ELF/NoteDetails/properties/X86ISA.hpp b/include/LIEF/ELF/NoteDetails/properties/X86ISA.hpp index 5f0d98d89d..0edd7d0b5b 100644 --- a/include/LIEF/ELF/NoteDetails/properties/X86ISA.hpp +++ b/include/LIEF/ELF/NoteDetails/properties/X86ISA.hpp @@ -19,6 +19,7 @@ #include #include "LIEF/ELF/NoteDetails/NoteGnuProperty.hpp" +#include "LIEF/visibility.h" namespace LIEF { namespace ELF { @@ -31,7 +32,7 @@ namespace ELF { /// - ``GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED`` /// - ``GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED`` /// - ``GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED`` -class X86ISA : public NoteGnuProperty::Property { +class LIEF_API X86ISA : public NoteGnuProperty::Property { public: enum class FLAG { NONE = 0, diff --git a/include/LIEF/MachO/BindingInfoIterator.hpp b/include/LIEF/MachO/BindingInfoIterator.hpp index 45f4acb842..8d748b0cb4 100644 --- a/include/LIEF/MachO/BindingInfoIterator.hpp +++ b/include/LIEF/MachO/BindingInfoIterator.hpp @@ -15,6 +15,7 @@ */ #ifndef LIEF_MACHO_BINDING_INFO_IT_H #define LIEF_MACHO_BINDING_INFO_IT_H +#include "LIEF/visibility.h" #include "LIEF/iterators.hpp" #include "LIEF/MachO/BindingInfo.hpp" @@ -24,7 +25,7 @@ class Binary; class DyldInfo; class DyldChainedFixups; -class BindingInfoIterator : +class LIEF_API BindingInfoIterator : public iterator_facade_base #include "LIEF/MachO/DyldChainedFormat.hpp" -#include "LIEF/config.h" #include "LIEF/errors.hpp" +#include "LIEF/visibility.h" namespace LIEF { class BinaryStream; namespace MachO { -class ChainedPointerAnalysis { +class LIEF_API ChainedPointerAnalysis { public: // DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E struct dyld_chained_ptr_arm64e_rebase_t @@ -37,7 +37,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_rebase_t& chain); uint64_t unpack_target() const { return uint64_t(high8) | target; @@ -54,7 +55,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_bind_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_bind_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E @@ -68,7 +70,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_rebase_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E @@ -83,7 +86,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_bind_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_bind_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_64 & DYLD_CHAINED_PTR_FORMAT::PTR_64_OFFSET @@ -95,7 +99,8 @@ class ChainedPointerAnalysis { next : 12, bind : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_rebase_t& chain); uint64_t unpack_target() const { return uint64_t(high8) | target; @@ -112,7 +117,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_bind24_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_bind24_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_ARM64E_USERLAND24 @@ -127,7 +133,8 @@ class ChainedPointerAnalysis { bind : 1, auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_bind24_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_arm64e_auth_bind24_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_64 @@ -139,7 +146,8 @@ class ChainedPointerAnalysis { next : 12, bind : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_bind_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_bind_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_64_KERNEL_CACHE @@ -153,7 +161,8 @@ class ChainedPointerAnalysis { next : 12, is_auth : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_kernel_cache_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_64_kernel_cache_rebase_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_32 @@ -163,7 +172,8 @@ class ChainedPointerAnalysis { next : 5, bind : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_rebase_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_32 @@ -174,7 +184,8 @@ class ChainedPointerAnalysis { next : 5, bind : 1; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_bind_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_bind_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_32_CACHE @@ -183,7 +194,8 @@ class ChainedPointerAnalysis { uint32_t target : 30, next : 2; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_cache_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_cache_rebase_t& chain); }; // DYLD_CHAINED_PTR_FORMAT::PTR_32_FIRMWARE @@ -192,7 +204,8 @@ class ChainedPointerAnalysis { uint32_t target : 26, next : 6; - friend std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_firmware_rebase_t& chain); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const dyld_chained_ptr_32_firmware_rebase_t& chain); }; enum class PTR_TYPE { @@ -368,7 +381,8 @@ class ChainedPointerAnalysis { } bool is_auth() const; - friend std::ostream& operator<<(std::ostream& os, const union_pointer_t& ptr); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const union_pointer_t& ptr); }; static_assert(sizeof(union_pointer_t) == 16); diff --git a/include/LIEF/MachO/LoadCommand.hpp b/include/LIEF/MachO/LoadCommand.hpp index e885d8503a..7ef62e9d2a 100644 --- a/include/LIEF/MachO/LoadCommand.hpp +++ b/include/LIEF/MachO/LoadCommand.hpp @@ -190,7 +190,7 @@ class LIEF_API LoadCommand : public Object { uint64_t command_offset_ = 0; }; -const char* to_string(LoadCommand::TYPE type); +LIEF_API const char* to_string(LoadCommand::TYPE type); } } diff --git a/include/LIEF/PE/signature/PKCS9TSTInfo.hpp b/include/LIEF/PE/signature/PKCS9TSTInfo.hpp index 1bb3564761..d200c895e9 100644 --- a/include/LIEF/PE/signature/PKCS9TSTInfo.hpp +++ b/include/LIEF/PE/signature/PKCS9TSTInfo.hpp @@ -19,6 +19,7 @@ #include #include "LIEF/Visitor.hpp" +#include "LIEF/visibility.h" #include "LIEF/PE/signature/ContentInfo.hpp" namespace LIEF { @@ -55,7 +56,7 @@ namespace PE { //! micros [1] INTEGER (1..999) OPTIONAL //! } //! ``` -class PKCS9TSTInfo : public ContentInfo::Content { +class LIEF_API PKCS9TSTInfo : public ContentInfo::Content { friend class SignatureParser; public: diff --git a/include/LIEF/range.hpp b/include/LIEF/range.hpp index d3c36562ed..91c9ad4a41 100644 --- a/include/LIEF/range.hpp +++ b/include/LIEF/range.hpp @@ -17,6 +17,8 @@ #include #include +#include "LIEF/visibility.h" + namespace LIEF { struct range_t { uint64_t low = 0; @@ -41,7 +43,8 @@ struct range_t { return !(lhs == rhs); } - friend std::ostream& operator<<(std::ostream& os, const range_t& range); + friend LIEF_API + std::ostream& operator<<(std::ostream& os, const range_t& range); }; }