Make sure required symbols are exported:

and use a standard mechanism that plays well with -fvisibility.
Given that several symbols now use declspec(dllexport), remove them from
the ad-hoc cling_exports in ROOT's CMakeLists.txt.
This commit is contained in:
Axel Naumann 2021-05-19 11:55:39 +02:00 committed by jenkins
parent fc5b3e6f16
commit 3bd3ff18cb
11 changed files with 141 additions and 6 deletions

View File

@ -9,9 +9,13 @@
#ifndef CLING_VALUEPRINTERC_H
#define CLING_VALUEPRINTERC_H
#include <cling/Interpreter/Visibility.h>
#ifdef __cplusplus
extern "C"
#endif
CLING_LIB_EXPORT
void cling_PrintValue(void* /*cling::Value**/ V);
#endif // CLING_VALUEPRINTERC_H

View File

@ -16,6 +16,7 @@
#include "cling/Interpreter/DynamicExprInfo.h"
#include "cling/Interpreter/DynamicLookupLifetimeHandler.h"
#include "cling/Interpreter/Value.h"
#include "cling/Interpreter/Visibility.h"
namespace cling {
@ -28,6 +29,7 @@ namespace runtime {
namespace internal {
/// \brief Outlined Evaluate() implementation to not include Interpreter.h
/// into the runtime.
CLING_LIB_EXPORT
Value EvaluateDynamicExpression(Interpreter* interp, DynamicExprInfo* DEI,
clang::DeclContext* DC);

View File

@ -14,6 +14,8 @@
#error "This file must not be included by compiled programs."
#endif
#include <cling/Interpreter/Visibility.h>
#include <memory>
#include <string>
#include <tuple>
@ -24,6 +26,7 @@ namespace cling {
class Value;
// General fallback - prints the address
CLING_LIB_EXPORT
std::string printValue(const void *ptr);
// Fallback for e.g. vector<bool>'s bit iterator:
@ -32,64 +35,90 @@ namespace cling {
inline std::string printValue(const T& val) { return "{not representable}"; }
// void pointer
CLING_LIB_EXPORT
std::string printValue(const void **ptr);
// Bool
CLING_LIB_EXPORT
std::string printValue(const bool *val);
// Chars
CLING_LIB_EXPORT
std::string printValue(const char *val);
CLING_LIB_EXPORT
std::string printValue(const signed char *val);
CLING_LIB_EXPORT
std::string printValue(const unsigned char *val);
CLING_LIB_EXPORT
std::string printValue(const char16_t *val);
CLING_LIB_EXPORT
std::string printValue(const char32_t *val);
CLING_LIB_EXPORT
std::string printValue(const wchar_t *val);
// Ints
CLING_LIB_EXPORT
std::string printValue(const short *val);
CLING_LIB_EXPORT
std::string printValue(const unsigned short *val);
CLING_LIB_EXPORT
std::string printValue(const int *val);
CLING_LIB_EXPORT
std::string printValue(const unsigned int *val);
CLING_LIB_EXPORT
std::string printValue(const long *val);
CLING_LIB_EXPORT
std::string printValue(const unsigned long *val);
CLING_LIB_EXPORT
std::string printValue(const long long *val);
CLING_LIB_EXPORT
std::string printValue(const unsigned long long *val);
// Reals
CLING_LIB_EXPORT
std::string printValue(const float *val);
CLING_LIB_EXPORT
std::string printValue(const double *val);
CLING_LIB_EXPORT
std::string printValue(const long double *val);
// Char pointers
CLING_LIB_EXPORT
std::string printValue(const char *const *val);
CLING_LIB_EXPORT
std::string printValue(const char **val);
// std::string
CLING_LIB_EXPORT
std::string printValue(const std::string *val);
CLING_LIB_EXPORT
std::string printValue(const std::wstring *val);
CLING_LIB_EXPORT
std::string printValue(const std::u16string *val);
CLING_LIB_EXPORT
std::string printValue(const std::u32string *val);
// constant unicode strings, i.e. u"String"
template <typename T>
CLING_LIB_EXPORT
std::string toUTF8(const T* const Src, size_t N, const char Prefix = 0);
template <size_t N>
@ -113,9 +142,11 @@ namespace cling {
}
// cling::Value
CLING_LIB_EXPORT
std::string printValue(const Value *value);
namespace valuePrinterInternal {
CLING_LIB_EXPORT
extern const char* const kEmptyCollection;
}
@ -123,7 +154,9 @@ namespace cling {
namespace collectionPrinterInternal {
// Forward declaration, so recursion of containers possible.
template <typename T> std::string printValue(const T* V, const void* = 0);
template <typename T>
CLING_LIB_EXPORT
std::string printValue(const T* V, const void* = 0);
template <typename T> inline std::string
printValue(const T& V, typename std::enable_if<

View File

@ -24,6 +24,7 @@
#ifdef __cplusplus
#include <cling/Interpreter/RuntimeOptions.h>
#include "cling/Interpreter/Visibility.h"
#include <new>
namespace cling {
@ -58,6 +59,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpSVR - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn);
///\brief Set the value of the GenericValue for the expression
@ -69,6 +71,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpSVR - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpV, void* vpQT, char vpOn,
float value);
@ -81,6 +84,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpSVR - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpV, void* vpQT, char vpOn,
double value);
@ -94,6 +98,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpSVR - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpV, void* vpQT, char vpOn,
long double value);
@ -108,6 +113,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpSVR - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpV, void* vpQT, char vpOn,
unsigned long long value);
@ -120,6 +126,7 @@ namespace cling {
///\param [in] vpT - The opaque ptr for the cling::Transaction.
///\param [out] vpV - The Value that is created.
///
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpV, void* vpQT, char vpOn,
const void* value);
@ -132,6 +139,7 @@ namespace cling {
///
///\returns the address where the value should be put.
///
CLING_LIB_EXPORT
void* setValueWithAlloc(void* vpI, void* vpV, void* vpQT, char vpOn);
///\brief Placement new doesn't work for arrays. It needs to be called on
@ -185,7 +193,7 @@ extern "C" {
/// the definition of the exceptions from the RuntimeUniverse and allows us to
/// run cling in -no-rtti mode.
///
CLING_LIB_EXPORT
void* cling_runtime_internal_throwIfInvalidPointer(void* Sema,
void* Expr,
const void* Arg);

View File

@ -10,6 +10,8 @@
#ifndef CLING_VALUE_H
#define CLING_VALUE_H
#include "cling/Interpreter/Visibility.h"
#include <stddef.h>
#include <stdint.h>
#include <type_traits>
@ -37,7 +39,7 @@ namespace cling {
/// clang::QualType. Use-cases are expression evaluation, value printing
/// and parameters for function calls.
///
class Value {
class CLING_LIB_EXPORT Value {
protected:
///\brief Multi-purpose storage.
///

View File

@ -0,0 +1,33 @@
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author: Axel Naumann <axel@cern.ch>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
#ifndef CLING_VISIBILITY_H
#define CLING_VISIBILITY_H
#include <new>
// Adapted from llvm/Support/Compiler.h
#ifndef __has_attribute
# define __has_attribute(x) 0
#endif
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
// Adapted from https://gcc.gnu.org/wiki/Visibility
# ifdef __GNUC__
# define CLING_LIB_EXPORT __attribute__ ((dllexport))
# else
# define CLING_LIB_EXPORT __declspec(dllexport)
# endif
#elif (__has_attribute(visibility))
# define CLING_LIB_EXPORT __attribute__ ((visibility("default")))
#else
# define CLING_LIB_EXPORT
#endif
#endif // CLING_VISIBILITY_H

View File

@ -12,5 +12,6 @@ module Cling_Runtime_Extra {
module "DynamicExprInfo.h" { header "Interpreter/DynamicExprInfo.h" export * }
module "DynamicLookupLifetimeHandler.h" { header "Interpreter/DynamicLookupLifetimeHandler.h" export * }
module "Value.h" { header "Interpreter/Value.h" export * }
module "Visibility.h" { header "Interpreter/Visibility.h" export * }
export *
}

View File

@ -12,6 +12,7 @@
#include "cling/Interpreter/InterpreterCallbacks.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/Visibility.h"
#include "cling/Utils/Validation.h"
#include "clang/Frontend/CompilerInstance.h"
@ -27,6 +28,7 @@ extern "C" {
///\returns void*, const-cast from Arg, to reduce the complexity in the
/// calling AST nodes, at the expense of possibly doing a
/// T* -> const void* -> const_cast<void*> -> T* round trip.
CLING_LIB_EXPORT
void* cling_runtime_internal_throwIfInvalidPointer(void* Interp, void* Expr,
const void* Arg) {

View File

@ -35,6 +35,7 @@
#include "cling/Interpreter/LookupHelper.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Interpreter/Value.h"
#include "cling/Interpreter/Visibility.h"
#include "cling/Utils/AST.h"
#include "cling/Utils/Casting.h"
#include "cling/Utils/Output.h"
@ -1818,6 +1819,7 @@ namespace cling {
namespace runtime {
namespace internal {
CLING_LIB_EXPORT
Value EvaluateDynamicExpression(Interpreter* interp, DynamicExprInfo* DEI,
clang::DeclContext* DC) {
Value ret = [&]

View File

@ -12,6 +12,7 @@
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Interpreter/Value.h"
#include "cling/Interpreter/Visibility.h"
#include "cling/Utils/AST.h"
#include "clang/AST/ASTContext.h"
@ -513,38 +514,51 @@ namespace {
namespace cling {
namespace runtime {
namespace internal {
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn) {
// In cases of void we 'just' need to change the type of the value.
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT);
}
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn,
float value) {
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT).getAs<float>() = value;
dumpIfNoStorage(vpSVR, vpOn);
}
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn,
double value) {
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT).getAs<double>() = value;
dumpIfNoStorage(vpSVR, vpOn);
}
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn,
long double value) {
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT).getAs<long double>()
= value;
dumpIfNoStorage(vpSVR, vpOn);
}
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn,
unsigned long long value) {
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT)
.getAs<unsigned long long>() = value;
dumpIfNoStorage(vpSVR, vpOn);
}
CLING_LIB_EXPORT
void setValueNoAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn,
const void* value){
allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT).getAs<void*>()
= const_cast<void*>(value);
dumpIfNoStorage(vpSVR, vpOn);
}
CLING_LIB_EXPORT
void* setValueWithAlloc(void* vpI, void* vpSVR, void* vpQT, char vpOn) {
return allocateStoredRefValueAndGetGV(vpI, vpSVR, vpQT).getAs<void*>();
}

View File

@ -16,6 +16,7 @@
#include "cling/Interpreter/LookupHelper.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Interpreter/Value.h"
#include "cling/Interpreter/Visibility.h"
#include "cling/Utils/AST.h"
#include "cling/Utils/Casting.h"
#include "cling/Utils/Output.h"
@ -53,7 +54,8 @@
using namespace cling;
// Implements the CValuePrinter interface.
extern "C" void cling_PrintValue(void * /*cling::Value* V*/) {
extern "C" CLING_LIB_EXPORT
void cling_PrintValue(void * /*cling::Value* V*/) {
//Value* value = (Value*)V;
//std::string typeStr = printTypeInternal(*value);
@ -63,6 +65,7 @@ extern "C" void cling_PrintValue(void * /*cling::Value* V*/) {
// Exported for RuntimePrintValue.h
namespace cling {
namespace valuePrinterInternal {
CLING_LIB_EXPORT
extern const char* const kEmptyCollection = "{}";
struct OpaqueString{};
@ -176,18 +179,20 @@ static std::string printAddress(const void* Ptr, const char Prfx = 0) {
} // anonymous namespace
namespace cling {
// General fallback - prints the address
CLING_LIB_EXPORT
std::string printValue(const void *ptr) {
return printAddress(ptr, '@');
}
// void pointer
CLING_LIB_EXPORT
std::string printValue(const void **ptr) {
return printAddress(*ptr);
}
// Bool
CLING_LIB_EXPORT
std::string printValue(const bool *val) {
return *val ? kTrueStr : kFalseStr;
}
@ -215,61 +220,72 @@ namespace cling {
return Strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const char *val) {
return printOneChar(*val);
}
CLING_LIB_EXPORT
std::string printValue(const signed char *val) {
return printOneChar(*val);
}
CLING_LIB_EXPORT
std::string printValue(const unsigned char *val) {
return printOneChar(*val);
}
// Ints
CLING_LIB_EXPORT
std::string printValue(const short *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const unsigned short *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const int *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const unsigned int *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const long *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const unsigned long *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const long long *val) {
cling::smallstream strm;
strm << *val;
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const unsigned long long *val) {
cling::smallstream strm;
strm << *val;
@ -277,18 +293,21 @@ namespace cling {
}
// Reals
CLING_LIB_EXPORT
std::string printValue(const float *val) {
cling::smallstream strm;
strm << llvm::format("%#.6g", *val) << 'f';
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const double *val) {
cling::smallstream strm;
strm << llvm::format("%#.8g", *val);
return strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const long double *val) {
cling::smallstream strm;
strm << llvm::format("%#.8Lg", *val) << 'L';
@ -297,7 +316,7 @@ namespace cling {
}
// Char pointers
std::string printString(const char *const *Ptr, size_t N = 10000) {
static std::string printString(const char *const *Ptr, size_t N = 10000) {
// Assumption is this is a string.
// N is limit to prevent endless loop if Ptr is not really a string.
@ -338,15 +357,18 @@ namespace cling {
return Strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const char *const *val) {
return printString(val);
}
CLING_LIB_EXPORT
std::string printValue(const char **val) {
return printString(val);
}
// std::string
CLING_LIB_EXPORT
std::string printValue(const std::string *val) {
return "\"" + *val + "\"";
}
@ -460,21 +482,25 @@ namespace cling {
// declaration: cling/Utils/UTF8.h & cling/Interpreter/RuntimePrintValue.h
template <class T>
CLING_LIB_EXPORT
std::string toUTF8(const T* const Str, size_t N, const char Prefix);
template <>
CLING_LIB_EXPORT
std::string toUTF8<char16_t>(const char16_t* const Str, size_t N,
const char Prefix) {
return utf8Value(Str, N, Prefix, encodeUTF8);
}
template <>
CLING_LIB_EXPORT
std::string toUTF8<char32_t>(const char32_t* const Str, size_t N,
const char Prefix) {
return utf8Value(Str, N, Prefix, encodeUTF8);
}
template <>
CLING_LIB_EXPORT
std::string toUTF8<wchar_t>(const wchar_t* const Str, size_t N,
const char Prefix) {
static_assert(sizeof(wchar_t) == sizeof(char16_t) ||
@ -487,6 +513,7 @@ namespace cling {
}
template <>
CLING_LIB_EXPORT
std::string toUTF8<char>(const char* const Str, size_t N, const char Prefix) {
return utf8Value(Str, N, Prefix, quoteString);
}
@ -500,14 +527,17 @@ namespace cling {
return encodeUTF8(Src->data(), Src->size(), Prefix);
}
CLING_LIB_EXPORT
std::string printValue(const std::u16string* Val) {
return toUTF8(Val, 'u');
}
CLING_LIB_EXPORT
std::string printValue(const std::u32string* Val) {
return toUTF8(Val, 'U');
}
CLING_LIB_EXPORT
std::string printValue(const std::wstring* Val) {
return toUTF8(Val, 'L');
}
@ -527,14 +557,17 @@ namespace cling {
return Strm.str();
}
CLING_LIB_EXPORT
std::string printValue(const char16_t *Val) {
return toUnicode(Val, 'u');
}
CLING_LIB_EXPORT
std::string printValue(const char32_t *Val) {
return toUnicode(Val, 'U');
}
CLING_LIB_EXPORT
std::string printValue(const wchar_t *Val) {
return toUnicode(Val, 'L', 'x');
}
@ -916,6 +949,7 @@ static std::string printUnpackedClingValue(const Value &V) {
namespace cling {
// cling::Value
CLING_LIB_EXPORT
std::string printValue(const Value *value) {
cling::smallstream strm;