Skip to content

Commit d528fe6

Browse files
committed
Add __attribute__((visibility("default"))) attribute to stop symbols being hidden when linking clangInterpreter library to other libraries during Emscripten build
Currently CppInterOp links its Emscripten shared library to the Emscripten static library libclangInterpreter.a . Certain symbols get hidden in libclangInterOp.a due to the -fvisibility-inlines-hidden flag when building an Emscripten build of llvm. This causes the CppInterOp to have to manually export these in a non Emscripten recommended way (see https://github.com/compiler-research/CppInterOp/blob/main/lib/CppInterOp/exports.ld ). This patch would allow us to avoid this method, by marking these symbols are visible, instead of hidden.
1 parent a74c7d8 commit d528fe6

File tree

18 files changed

+82
-59
lines changed

18 files changed

+82
-59
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,7 @@ void ASTContext::adjustExceptionSpec(
38953895

38963896
/// getComplexType - Return the uniqued reference to the type for a complex
38973897
/// number with the specified element type.
3898-
QualType ASTContext::getComplexType(QualType T) const {
3898+
LLVM_ABI QualType ASTContext::getComplexType(QualType T) const {
38993899
// Unique pointers, to guarantee there is only one pointer of a particular
39003900
// structure.
39013901
llvm::FoldingSetNodeID ID;
@@ -4079,7 +4079,7 @@ QualType ASTContext::getBlockPointerType(QualType T) const {
40794079

40804080
/// getLValueReferenceType - Return the uniqued reference to the type for an
40814081
/// lvalue reference to the specified type.
4082-
QualType
4082+
LLVM_ABI QualType
40834083
ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const {
40844084
assert((!T->isPlaceholderType() ||
40854085
T->isSpecificPlaceholderType(BuiltinType::UnknownAny)) &&
@@ -5251,7 +5251,7 @@ QualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl,
52515251

52525252
/// getTypeDeclType - Return the unique reference to the type for the
52535253
/// specified type declaration.
5254-
QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const {
5254+
LLVM_ABI QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const {
52555255
assert(Decl && "Passed null for Decl param");
52565256
assert(!Decl->TypeForDecl && "TypeForDecl present in slow case");
52575257

@@ -13125,7 +13125,7 @@ VTableContextBase *ASTContext::getVTableContext() {
1312513125
return VTContext.get();
1312613126
}
1312713127

13128-
MangleContext *ASTContext::createMangleContext(const TargetInfo *T) {
13128+
LLVM_ABI MangleContext *ASTContext::createMangleContext(const TargetInfo *T) {
1312913129
if (!T)
1313013130
T = Target;
1313113131
switch (T->getCXXABI().getKind()) {

clang/lib/AST/Decl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "llvm/ADT/StringSwitch.h"
6060
#include "llvm/ADT/iterator_range.h"
6161
#include "llvm/Support/Casting.h"
62+
#include "llvm/Support/Compiler.h"
6263
#include "llvm/Support/ErrorHandling.h"
6364
#include "llvm/Support/raw_ostream.h"
6465
#include "llvm/TargetParser/Triple.h"
@@ -2255,7 +2256,7 @@ bool VarDecl::isInExternCXXContext() const {
22552256

22562257
VarDecl *VarDecl::getCanonicalDecl() { return getFirstDecl(); }
22572258

2258-
VarDecl::DefinitionKind
2259+
LLVM_ABI VarDecl::DefinitionKind
22592260
VarDecl::isThisDeclarationADefinition(ASTContext &C) const {
22602261
if (isThisDeclarationADemotedDefinition())
22612262
return DeclarationOnly;
@@ -3763,7 +3764,7 @@ unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const {
37633764
/// getNumParams - Return the number of parameters this function must have
37643765
/// based on its FunctionType. This is the length of the ParamInfo array
37653766
/// after it has been created.
3766-
unsigned FunctionDecl::getNumParams() const {
3767+
LLVM_ABI unsigned FunctionDecl::getNumParams() const {
37673768
const auto *FPT = getType()->getAs<FunctionProtoType>();
37683769
return FPT ? FPT->getNumParams() : 0;
37693770
}
@@ -4200,7 +4201,7 @@ bool FunctionDecl::isTemplateInstantiation() const {
42004201
return clang::isTemplateInstantiation(getTemplateSpecializationKind());
42014202
}
42024203

4203-
FunctionDecl *
4204+
LLVM_ABI FunctionDecl *
42044205
FunctionDecl::getTemplateInstantiationPattern(bool ForDefinition) const {
42054206
// If this is a generic lambda call operator specialization, its
42064207
// instantiation pattern is always its primary template's pattern
@@ -4265,7 +4266,7 @@ FunctionDecl::getTemplateSpecializationInfo() const {
42654266
TemplateOrSpecialization);
42664267
}
42674268

4268-
const TemplateArgumentList *
4269+
LLVM_ABI const TemplateArgumentList *
42694270
FunctionDecl::getTemplateSpecializationArgs() const {
42704271
if (FunctionTemplateSpecializationInfo *Info =
42714272
dyn_cast_if_present<FunctionTemplateSpecializationInfo *>(
@@ -5143,7 +5144,7 @@ RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C,
51435144
return R;
51445145
}
51455146

5146-
bool RecordDecl::isInjectedClassName() const {
5147+
LLVM_ABI bool RecordDecl::isInjectedClassName() const {
51475148
return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
51485149
cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
51495150
}

clang/lib/AST/DeclBase.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "clang/Basic/TargetInfo.h"
3838
#include "llvm/ADT/PointerIntPair.h"
3939
#include "llvm/ADT/StringRef.h"
40+
#include "llvm/Support/Compiler.h"
4041
#include "llvm/Support/ErrorHandling.h"
4142
#include "llvm/Support/MathExtras.h"
4243
#include "llvm/Support/VersionTuple.h"
@@ -526,7 +527,7 @@ TranslationUnitDecl *Decl::getTranslationUnitDecl() {
526527
return cast<TranslationUnitDecl>(DC);
527528
}
528529

529-
ASTContext &Decl::getASTContext() const {
530+
LLVM_ABI ASTContext &Decl::getASTContext() const {
530531
return getTranslationUnitDecl()->getASTContext();
531532
}
532533

@@ -613,7 +614,7 @@ ExternalSourceSymbolAttr *Decl::getExternalSourceSymbolAttr() const {
613614
return nullptr;
614615
}
615616

616-
bool Decl::hasDefiningAttr() const {
617+
LLVM_ABI bool Decl::hasDefiningAttr() const {
617618
return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>() ||
618619
hasAttr<LoaderUninitializedAttr>();
619620
}
@@ -1047,7 +1048,7 @@ void Decl::addAttr(Attr *A) {
10471048
Attrs.insert(I, A);
10481049
}
10491050

1050-
const AttrVec &Decl::getAttrs() const {
1051+
LLVM_ABI const AttrVec &Decl::getAttrs() const {
10511052
assert(HasAttrs && "No attrs to get!");
10521053
return getASTContext().getDeclAttrs(this);
10531054
}
@@ -1065,7 +1066,7 @@ Decl *Decl::castFromDeclContext (const DeclContext *D) {
10651066
}
10661067
}
10671068

1068-
DeclContext *Decl::castToDeclContext(const Decl *D) {
1069+
LLVM_ABI DeclContext *Decl::castToDeclContext(const Decl *D) {
10691070
Decl::Kind DK = D->getKind();
10701071
switch(DK) {
10711072
#define DECL(NAME, BASE)
@@ -1291,7 +1292,7 @@ DeclContext::DeclContext(Decl::Kind K) {
12911292
setUseQualifiedLookup(false);
12921293
}
12931294

1294-
bool DeclContext::classof(const Decl *D) {
1295+
LLVM_ABI bool DeclContext::classof(const Decl *D) {
12951296
Decl::Kind DK = D->getKind();
12961297
switch (DK) {
12971298
#define DECL(NAME, BASE)
@@ -1662,7 +1663,7 @@ ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC,
16621663
return List.getLookupResult();
16631664
}
16641665

1665-
DeclContext::decl_iterator DeclContext::decls_begin() const {
1666+
LLVM_ABI DeclContext::decl_iterator DeclContext::decls_begin() const {
16661667
if (hasExternalLexicalStorage())
16671668
LoadLexicalDeclsFromExternalStorage();
16681669
return decl_iterator(FirstDecl);
@@ -1891,7 +1892,7 @@ void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
18911892
}
18921893
}
18931894

1894-
DeclContext::lookup_result
1895+
LLVM_ABI DeclContext::lookup_result
18951896
DeclContext::lookup(DeclarationName Name) const {
18961897
// For transparent DeclContext, we should lookup in their enclosing context.
18971898
if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)

clang/lib/AST/DeclTemplate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/ADT/PointerUnion.h"
3232
#include "llvm/ADT/STLExtras.h"
3333
#include "llvm/ADT/SmallVector.h"
34+
#include "llvm/Support/Compiler.h"
3435
#include "llvm/Support/ErrorHandling.h"
3536
#include <cassert>
3637
#include <optional>
@@ -549,6 +550,7 @@ void ClassTemplateDecl::LoadLazySpecializations(
549550
loadLazySpecializationsImpl(OnlyPartial);
550551
}
551552

553+
LLVM_ABI
552554
llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
553555
ClassTemplateDecl::getSpecializations() const {
554556
LoadLazySpecializations();
@@ -1451,7 +1453,8 @@ void VarTemplateSpecializationDecl::getNameForDiagnostic(
14511453
}
14521454
}
14531455

1454-
VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {
1456+
LLVM_ABI VarTemplateDecl *
1457+
VarTemplateSpecializationDecl::getSpecializedTemplate() const {
14551458
if (const auto *PartialSpec =
14561459
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
14571460
return PartialSpec->PartialSpecialization->getSpecializedTemplate();

clang/lib/AST/Mangle.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/StringExtras.h"
2424
#include "llvm/IR/DataLayout.h"
2525
#include "llvm/IR/Mangler.h"
26+
#include "llvm/Support/Compiler.h"
2627
#include "llvm/Support/ErrorHandling.h"
2728
#include "llvm/Support/Format.h"
2829
#include "llvm/Support/raw_ostream.h"
@@ -118,7 +119,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context,
118119
}
119120
}
120121

121-
bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
122+
LLVM_ABI bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
122123
const ASTContext &ASTContext = getASTContext();
123124

124125
CCMangling CC = getCallingConvMangling(ASTContext, D);
@@ -152,7 +153,7 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) {
152153
return shouldMangleCXXName(D);
153154
}
154155

155-
void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
156+
LLVM_ABI void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
156157
const ASTContext &ASTContext = getASTContext();
157158
const NamedDecl *D = cast<NamedDecl>(GD.getDecl());
158159

clang/lib/AST/Type.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/ADT/FoldingSet.h"
4545
#include "llvm/ADT/STLExtras.h"
4646
#include "llvm/ADT/SmallVector.h"
47+
#include "llvm/Support/Compiler.h"
4748
#include "llvm/Support/ErrorHandling.h"
4849
#include "llvm/Support/MathExtras.h"
4950
#include <algorithm>
@@ -650,7 +651,7 @@ template <> const CountAttributedType *Type::getAs() const {
650651
/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
651652
/// sugar off the given type. This should produce an object of the
652653
/// same dynamic type as the canonical type.
653-
const Type *Type::getUnqualifiedDesugaredType() const {
654+
LLVM_ABI const Type *Type::getUnqualifiedDesugaredType() const {
654655
const Type *Cur = this;
655656

656657
while (true) {
@@ -2302,7 +2303,7 @@ bool Type::hasUnsignedIntegerRepresentation() const {
23022303
return isUnsignedIntegerOrEnumerationType();
23032304
}
23042305

2305-
bool Type::isFloatingType() const {
2306+
LLVM_ABI bool Type::isFloatingType() const {
23062307
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
23072308
return BT->isFloatingPoint();
23082309
if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
@@ -4227,7 +4228,9 @@ static TagDecl *getInterestingTagDecl(TagDecl *decl) {
42274228
return decl;
42284229
}
42294230

4230-
TagDecl *TagType::getDecl() const { return getInterestingTagDecl(decl); }
4231+
LLVM_ABI TagDecl *TagType::getDecl() const {
4232+
return getInterestingTagDecl(decl);
4233+
}
42314234

42324235
bool TagType::isBeingDefined() const { return getDecl()->isBeingDefined(); }
42334236

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
5050
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
5151
#include "llvm/IR/Module.h"
52+
#include "llvm/Support/Compiler.h"
5253
#include "llvm/Support/Errc.h"
5354
#include "llvm/Support/ErrorHandling.h"
5455
#include "llvm/Support/raw_ostream.h"
@@ -194,6 +195,7 @@ IncrementalCompilerBuilder::create(std::string TT,
194195
return CreateCI(**ErrOrCC1Args);
195196
}
196197

198+
LLVM_ABI
197199
llvm::Expected<std::unique_ptr<CompilerInstance>>
198200
IncrementalCompilerBuilder::CreateCpp() {
199201
std::vector<const char *> Argv;
@@ -524,7 +526,9 @@ const CompilerInstance *Interpreter::getCompilerInstance() const {
524526
return CI.get();
525527
}
526528

527-
CompilerInstance *Interpreter::getCompilerInstance() { return CI.get(); }
529+
LLVM_ABI CompilerInstance *Interpreter::getCompilerInstance() {
530+
return CI.get();
531+
}
528532

529533
llvm::Expected<llvm::orc::LLJIT &> Interpreter::getExecutionEngine() {
530534
if (!IncrExecutor) {
@@ -577,7 +581,7 @@ Interpreter::RegisterPTU(TranslationUnitDecl *TU,
577581
return LastPTU;
578582
}
579583

580-
llvm::Expected<PartialTranslationUnit &>
584+
LLVM_ABI llvm::Expected<PartialTranslationUnit &>
581585
Interpreter::Parse(llvm::StringRef Code) {
582586
// If we have a device parser, parse it first. The generated code will be
583587
// included in the host compilation
@@ -673,7 +677,7 @@ llvm::Error Interpreter::CreateExecutor() {
673677

674678
void Interpreter::ResetExecutor() { IncrExecutor.reset(); }
675679

676-
llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
680+
LLVM_ABI llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
677681
assert(T.TheModule);
678682
LLVM_DEBUG(
679683
llvm::dbgs() << "execute-ptu "

clang/lib/Interpreter/InterpreterValuePrinter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "clang/Interpreter/Value.h"
2121
#include "clang/Sema/Lookup.h"
2222
#include "clang/Sema/Sema.h"
23-
23+
#include "llvm/Support/Compiler.h"
2424
#include "llvm/Support/Error.h"
2525
#include "llvm/Support/raw_ostream.h"
2626

@@ -300,16 +300,17 @@ llvm::Expected<Expr *> Interpreter::ExtractValueFromExpr(Expr *E) {
300300
using namespace clang;
301301

302302
// Temporary rvalue struct that need special care.
303-
REPL_EXTERNAL_VISIBILITY void *
303+
REPL_EXTERNAL_VISIBILITY LLVM_ABI void *
304304
__clang_Interpreter_SetValueWithAlloc(void *This, void *OutVal,
305305
void *OpaqueType) {
306306
Value &VRef = *(Value *)OutVal;
307307
VRef = Value(static_cast<Interpreter *>(This), OpaqueType);
308308
return VRef.getPtr();
309309
}
310310

311-
extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc(
312-
void *This, void *OutVal, void *OpaqueType, ...) {
311+
extern "C" LLVM_ABI void REPL_EXTERNAL_VISIBILITY
312+
__clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal, void *OpaqueType,
313+
...) {
313314
Value &VRef = *(Value *)OutVal;
314315
Interpreter *I = static_cast<Interpreter *>(This);
315316
VRef = Value(I, OpaqueType);

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/ADT/ArrayRef.h"
5151
#include "llvm/ADT/STLExtras.h"
5252
#include "llvm/ADT/StringExtras.h"
53+
#include "llvm/Support/Compiler.h"
5354
#include "llvm/Support/ConvertUTF.h"
5455
#include "llvm/Support/SaveAndRestore.h"
5556
#include <map>
@@ -11959,7 +11960,7 @@ EnumDecl *Sema::getStdAlignValT() const {
1195911960
return cast_or_null<EnumDecl>(StdAlignValT.get(Context.getExternalSource()));
1196011961
}
1196111962

11962-
NamespaceDecl *Sema::getStdNamespace() const {
11963+
LLVM_ABI NamespaceDecl *Sema::getStdNamespace() const {
1196311964
return cast_or_null<NamespaceDecl>(
1196411965
StdNamespace.get(Context.getExternalSource()));
1196511966
}

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ template <class Size_T> class SmallVectorBase {
8686
/// capacity for.
8787
///
8888
/// This does not construct or destroy any elements in the vector.
89-
void set_size(size_t N) {
89+
LLVM_ABI void set_size(size_t N) {
9090
assert(N <= capacity()); // implies no overflow in assignment
9191
Size = static_cast<Size_T>(N);
9292
}

0 commit comments

Comments
 (0)