Skip to content

Commit

Permalink
Fine grain control over some symbol visibility
Browse files Browse the repository at this point in the history
Setting -fvisibility=hidden when compiling Target libs has the advantage of
not being intrusive on the codebase, but it also sets the visibility of all
functions within header-only component like ADT. In the end, we end up with
some symbols with hidden visibility within llvm dylib (through the target libs),
and some with external visibility (through other libs). This paves the way for
subtle bugs like https://reviews.llvm.org/D101972

This patch explicitly set the visibility of some classes to `default` so that
`llvm::Any` related symbols keep a `default` visibility. Indeed a template
function with `default` visibility parametrized by a type with `hidden`
visibility is granted `hidden` visibility, and we don't want this for the
uniqueness of `llvm::Any::TypeId`.

Differential Revision: https://reviews.llvm.org/D108943
  • Loading branch information
serge-sans-paille committed Sep 1, 2021
1 parent 5ae6804 commit 02df443
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/LazyCallGraph.h
Expand Up @@ -419,7 +419,7 @@ class LazyCallGraph {
/// outer structure. SCCs do not support mutation of the call graph, that
/// must be done through the containing \c RefSCC in order to fully reason
/// about the ordering and connections of the graph.
class SCC {
class LLVM_EXTERNAL_VISIBILITY SCC {
friend class LazyCallGraph;
friend class LazyCallGraph::Node;

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/LoopInfo.h
Expand Up @@ -527,7 +527,7 @@ extern template class LoopBase<BasicBlock, Loop>;

/// Represents a single loop in the control flow graph. Note that not all SCCs
/// in the CFG are necessarily loops.
class Loop : public LoopBase<BasicBlock, Loop> {
class LLVM_EXTERNAL_VISIBILITY Loop : public LoopBase<BasicBlock, Loop> {
public:
/// A range representing the start and end location of a loop.
class LocRange {
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/LoopNestAnalysis.h
Expand Up @@ -25,7 +25,7 @@ using LoopVectorTy = SmallVector<Loop *, 8>;
class LPMUpdater;

/// This class represents a loop nest and can be used to query its properties.
class LoopNest {
class LLVM_EXTERNAL_VISIBILITY LoopNest {
public:
using InstrVectorTy = SmallVector<const Instruction *>;

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachineFunction.h
Expand Up @@ -227,7 +227,7 @@ struct LandingPadInfo {
: LandingPadBlock(MBB) {}
};

class MachineFunction {
class LLVM_EXTERNAL_VISIBILITY MachineFunction {
Function &F;
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/IR/Function.h
Expand Up @@ -58,7 +58,8 @@ class User;
class BranchProbabilityInfo;
class BlockFrequencyInfo;

class Function : public GlobalObject, public ilist_node<Function> {
class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
public ilist_node<Function> {
public:
using BasicBlockListType = SymbolTableList<BasicBlock>;

Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/Module.h
Expand Up @@ -64,9 +64,9 @@ class VersionTuple;
/// constant references to global variables in the module. When a global
/// variable is destroyed, it should have no entries in the GlobalValueRefMap.
/// The main container class for the LLVM Intermediate Representation.
class Module {
/// @name Types And Enumerations
/// @{
class LLVM_EXTERNAL_VISIBILITY Module {
/// @name Types And Enumerations
/// @{
public:
/// The type for the list of global variables.
using GlobalListType = SymbolTableList<GlobalVariable>;
Expand Down

0 comments on commit 02df443

Please sign in to comment.