llvm.org GIT mirror llvm / 38f68c5
Decouple dllexport/dllimport from linkage Representing dllexport/dllimport as distinct linkage types prevents using these attributes on templates and inline functions. Instead of introducing further mixed linkage types to include linkonce and weak ODR, the old import/export linkage types are replaced with a new separate visibility-like specifier: define available_externally dllimport void @f() {} @Var = dllexport global i32 1, align 4 Linkage for dllexported globals and functions is now equal to their linkage without dllexport. Imported globals and functions must be either declarations with external linkage, or definitions with AvailableExternallyLinkage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199218 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Rieck 6 years ago
27 changed file(s) with 547 addition(s) and 157 deletion(s). Raw diff Collapse all Expand all
657657 MODULE_CODE_GLOBALVAR Record
658658 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
659659
660 ``[GLOBALVAR, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr]``
660 ``[GLOBALVAR, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr, dllstorageclass]``
661661
662662 The ``GLOBALVAR`` record (code 7) marks the declaration or definition of a
663663 global variable. The operand fields are:
712712 * *unnamed_addr*: If present and non-zero, indicates that the variable has
713713 ``unnamed_addr``
714714
715 .. _dllstorageclass:
716
717 * *dllstorageclass*: If present, an encoding of the DLL storage class of this variable:
718
719 * ``default``: code 0
720 * ``dllimport``: code 1
721 * ``dllexport``: code 2
722
715723 .. _FUNCTION:
716724
717725 MODULE_CODE_FUNCTION Record
718726 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
719727
720 ``[FUNCTION, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prefix]``
728 ``[FUNCTION, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prefix, dllstorageclass]``
721729
722730 The ``FUNCTION`` record (code 8) marks the declaration or definition of a
723731 function. The operand fields are:
761769 * *prefix*: If non-zero, the value index of the prefix data for this function,
762770 plus 1.
763771
772 * *dllstorageclass*: An encoding of the `dllstorageclass`_ of this function
773
764774 MODULE_CODE_ALIAS Record
765775 ^^^^^^^^^^^^^^^^^^^^^^^^
766776
767 ``[ALIAS, alias type, aliasee val#, linkage, visibility]``
777 ``[ALIAS, alias type, aliasee val#, linkage, visibility, dllstorageclass]``
768778
769779 The ``ALIAS`` record (code 9) marks the definition of an alias. The operand
770780 fields are
776786 * *linkage*: An encoding of the `linkage type`_ for this alias
777787
778788 * *visibility*: If present, an encoding of the `visibility`_ of the alias
789
790 * *dllstorageclass*: If present, an encoding of the `dllstorageclass`_ of the alias
779791
780792 MODULE_CODE_PURGEVALS Record
781793 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
273273 visible, meaning that it participates in linkage and can be used to
274274 resolve external symbol references.
275275
276 The next two types of linkage are targeted for Microsoft Windows
277 platform only. They are designed to support importing (exporting)
278 symbols from (to) DLLs (Dynamic Link Libraries).
279
280 ``dllimport``
281 "``dllimport``" linkage causes the compiler to reference a function
282 or variable via a global pointer to a pointer that is set up by the
283 DLL exporting the symbol. On Microsoft Windows targets, the pointer
284 name is formed by combining ``__imp_`` and the function or variable
285 name.
286 ``dllexport``
287 "``dllexport``" linkage causes the compiler to provide a global
288 pointer to a pointer in a DLL, so that it can be referenced with the
289 ``dllimport`` attribute. On Microsoft Windows targets, the pointer
290 name is formed by combining ``__imp_`` and the function or variable
291 name. Since this linkage exists for defining a dll interface, the
292 compiler, assembler and linker know it is externally referenced and
293 must refrain from deleting the symbol.
294
295276 It is illegal for a function *declaration* to have any linkage type
296 other than ``external``, ``dllimport`` or ``extern_weak``.
277 other than ``external`` or ``extern_weak``.
297278
298279 .. _callingconv:
299280
415396
416397 .. _namedtypes:
417398
399 DLL Storage Classes
400 -------------------
401
402 All Global Variables, Functions and Aliases can have one of the following
403 DLL storage class:
404
405 ``dllimport``
406 "``dllimport``" causes the compiler to reference a function or variable via
407 a global pointer to a pointer that is set up by the DLL exporting the
408 symbol. On Microsoft Windows targets, the pointer name is formed by
409 combining ``__imp_`` and the function or variable name.
410 ``dllexport``
411 "``dllexport``" causes the compiler to provide a global pointer to a pointer
412 in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
413 Microsoft Windows targets, the pointer name is formed by combining
414 ``__imp_`` and the function or variable name. Since this storage class
415 exists for defining a dll interface, the compiler, assembler and linker know
416 it is externally referenced and must refrain from deleting the symbol.
417
418418 Named Types
419419 -----------
420420
528528 iterate over them as an array, alignment padding would break this
529529 iteration.
530530
531 Globals can also have a :ref:`DLL storage class `.
532
533 Syntax::
534
535 [@ =] [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
536 [AddrSpace] [unnamed_addr] [ExternallyInitialized]
537
538 [, section "name"] [, align ]
539
531540 For example, the following defines a global in a numbered address space
532541 with an initializer, section, and alignment:
533542
555564
556565 LLVM function definitions consist of the "``define``" keyword, an
557566 optional :ref:`linkage type `, an optional :ref:`visibility
558 style `, an optional :ref:`calling convention >`,
567 style `, an optional :ref:`DLL storage class >`,
568 an optional :ref:`calling convention `,
559569 an optional ``unnamed_addr`` attribute, a return type, an optional
560570 :ref:`parameter attribute ` for the return type, a function
561571 name, a (possibly empty) argument list (each with optional :ref:`parameter
566576
567577 LLVM function declarations consist of the "``declare``" keyword, an
568578 optional :ref:`linkage type `, an optional :ref:`visibility
569 style `, an optional :ref:`calling convention >`,
579 style `, an optional :ref:`DLL storage class >`,
580 an optional :ref:`calling convention `,
570581 an optional ``unnamed_addr`` attribute, a return type, an optional
571582 :ref:`parameter attribute ` for the return type, a function
572583 name, a possibly empty list of arguments, an optional alignment, an optional
602613
603614 Syntax::
604615
605 define [linkage] [visibility]
616 define [linkage] [visibility] [DLLStorageClass]
606617 [cconv] [ret attrs]
607618 @ ([argument list])
608619 [fn Attrs] [section "name"] [align N]
615626
616627 Aliases act as "second name" for the aliasee value (which can be either
617628 function, global variable, another alias or bitcast of global value).
618 Aliases may have an optional :ref:`linkage type `, and an optional
619 :ref:`visibility style `.
629 Aliases may have an optional :ref:`linkage type `, an optional
630 :ref:`visibility style `, and an optional :ref:`DLL storage class
631 `.
620632
621633 Syntax::
622634
623 @ = alias [Linkage] [Visibility] @
635 @ = [Visibility] [DLLStorageClass] alias [Linkage] @
624636
625637 The linkage must be one of ``private``, ``linker_private``,
626638 ``linker_private_weak``, ``internal``, ``linkonce``, ``weak``,
4141 PrivateLinkage, ///< Like Internal, but omit from symbol table.
4242 LinkerPrivateLinkage, ///< Like Private, but linker removes.
4343 LinkerPrivateWeakLinkage, ///< Like LinkerPrivate, but weak.
44 DLLImportLinkage, ///< Function to be imported from DLL
45 DLLExportLinkage, ///< Function to be accessible from DLL.
4644 ExternalWeakLinkage,///< ExternalWeak linkage description.
4745 CommonLinkage ///< Tentative definitions.
4846 };
5452 ProtectedVisibility ///< The GV is protected
5553 };
5654
55 /// @brief Storage classes of global values for PE targets.
56 enum DLLStorageClassTypes {
57 DefaultStorageClass = 0,
58 DLLImportStorageClass = 1, ///< Function to be imported from DLL
59 DLLExportStorageClass = 2 ///< Function to be accessible from DLL.
60 };
61
5762 protected:
5863 GlobalValue(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps,
5964 LinkageTypes linkage, const Twine &Name)
6065 : Constant(ty, vty, Ops, NumOps), Linkage(linkage),
61 Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0), Parent(0) {
66 Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0),
67 DllStorageClass(DefaultStorageClass), Parent(0) {
6268 setName(Name);
6369 }
6470
6874 unsigned Visibility : 2; // The visibility style of this global
6975 unsigned Alignment : 16; // Alignment of this symbol, must be power of two
7076 unsigned UnnamedAddr : 1; // This value's address is not significant
77 unsigned DllStorageClass : 2; // DLL storage class
7178 Module *Parent; // The containing module.
7279 std::string Section; // Section to emit this into, empty mean default
7380 public:
9097 return Visibility == ProtectedVisibility;
9198 }
9299 void setVisibility(VisibilityTypes V) { Visibility = V; }
93
100
101 DLLStorageClassTypes getDLLStorageClass() const {
102 return DLLStorageClassTypes(DllStorageClass);
103 }
104 bool hasDLLImportStorageClass() const {
105 return DllStorageClass == DLLImportStorageClass;
106 }
107 bool hasDLLExportStorageClass() const {
108 return DllStorageClass == DLLExportStorageClass;
109 }
110 void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
111
94112 bool hasSection() const { return !Section.empty(); }
95113 const std::string &getSection() const { return Section; }
96114 void setSection(StringRef S) { Section = S; }
144162 static bool isLocalLinkage(LinkageTypes Linkage) {
145163 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
146164 isLinkerPrivateLinkage(Linkage) || isLinkerPrivateWeakLinkage(Linkage);
147 }
148 static bool isDLLImportLinkage(LinkageTypes Linkage) {
149 return Linkage == DLLImportLinkage;
150 }
151 static bool isDLLExportLinkage(LinkageTypes Linkage) {
152 return Linkage == DLLExportLinkage;
153165 }
154166 static bool isExternalWeakLinkage(LinkageTypes Linkage) {
155167 return Linkage == ExternalWeakLinkage;
208220 return isLinkerPrivateWeakLinkage(Linkage);
209221 }
210222 bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
211 bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
212 bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
213223 bool hasExternalWeakLinkage() const { return isExternalWeakLinkage(Linkage); }
214224 bool hasCommonLinkage() const { return isCommonLinkage(Linkage); }
215225
283283 LLVMInternalLinkage, /**< Rename collisions when linking (static
284284 functions) */
285285 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
286 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
287 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
286 LLVMDLLImportLinkage, /**< Obsolete */
287 LLVMDLLExportLinkage, /**< Obsolete */
288288 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
289289 LLVMGhostLinkage, /**< Obsolete */
290290 LLVMCommonLinkage, /**< Tentative definitions */
241241
242242 // The Global variable production with no name can have many different
243243 // optional leading prefixes, the production is:
244 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
245 // OptionalAddrSpace OptionalUnNammedAddr
244 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalDLLStorageClass
245 // OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
246246 // ('constant'|'global') ...
247247 case lltok::kw_private: // OptionalLinkage
248248 case lltok::kw_linker_private: // OptionalLinkage
253253 case lltok::kw_linkonce: // OptionalLinkage
254254 case lltok::kw_linkonce_odr: // OptionalLinkage
255255 case lltok::kw_appending: // OptionalLinkage
256 case lltok::kw_dllexport: // OptionalLinkage
257256 case lltok::kw_common: // OptionalLinkage
258 case lltok::kw_dllimport: // OptionalLinkage
259257 case lltok::kw_extern_weak: // OptionalLinkage
260258 case lltok::kw_external: { // OptionalLinkage
261 unsigned Linkage, Visibility;
259 unsigned Linkage, Visibility, DLLStorageClass;
262260 if (ParseOptionalLinkage(Linkage) ||
263261 ParseOptionalVisibility(Visibility) ||
264 ParseGlobal("", SMLoc(), Linkage, true, Visibility))
262 ParseOptionalDLLStorageClass(DLLStorageClass) ||
263 ParseGlobal("", SMLoc(), Linkage, true, Visibility, DLLStorageClass))
265264 return true;
266265 break;
267266 }
268267 case lltok::kw_default: // OptionalVisibility
269268 case lltok::kw_hidden: // OptionalVisibility
270269 case lltok::kw_protected: { // OptionalVisibility
271 unsigned Visibility;
270 unsigned Visibility, DLLStorageClass;
272271 if (ParseOptionalVisibility(Visibility) ||
273 ParseGlobal("", SMLoc(), 0, false, Visibility))
272 ParseOptionalDLLStorageClass(DLLStorageClass) ||
273 ParseGlobal("", SMLoc(), 0, false, Visibility, DLLStorageClass))
274274 return true;
275275 break;
276276 }
279279 case lltok::kw_addrspace: // OptionalAddrSpace
280280 case lltok::kw_constant: // GlobalType
281281 case lltok::kw_global: // GlobalType
282 if (ParseGlobal("", SMLoc(), 0, false, 0)) return true;
282 if (ParseGlobal("", SMLoc(), 0, false, 0, 0)) return true;
283283 break;
284284
285285 case lltok::kw_attributes: if (ParseUnnamedAttrGrp()) return true; break;
445445
446446 /// ParseUnnamedGlobal:
447447 /// OptionalVisibility ALIAS ...
448 /// OptionalLinkage OptionalVisibility ... -> global variable
448 /// OptionalLinkage OptionalVisibility OptionalDLLStorageClass
449 /// ... -> global variable
449450 /// GlobalID '=' OptionalVisibility ALIAS ...
450 /// GlobalID '=' OptionalLinkage OptionalVisibility ... -> global variable
451 /// GlobalID '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
452 /// ... -> global variable
451453 bool LLParser::ParseUnnamedGlobal() {
452454 unsigned VarID = NumberedVals.size();
453455 std::string Name;
465467 }
466468
467469 bool HasLinkage;
468 unsigned Linkage, Visibility;
470 unsigned Linkage, Visibility, DLLStorageClass;
469471 if (ParseOptionalLinkage(Linkage, HasLinkage) ||
470 ParseOptionalVisibility(Visibility))
472 ParseOptionalVisibility(Visibility) ||
473 ParseOptionalDLLStorageClass(DLLStorageClass))
471474 return true;
472475
473476 if (HasLinkage || Lex.getKind() != lltok::kw_alias)
474 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
475 return ParseAlias(Name, NameLoc, Visibility);
477 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
478 DLLStorageClass);
479 return ParseAlias(Name, NameLoc, Visibility, DLLStorageClass);
476480 }
477481
478482 /// ParseNamedGlobal:
479483 /// GlobalVar '=' OptionalVisibility ALIAS ...
480 /// GlobalVar '=' OptionalLinkage OptionalVisibility ... -> global variable
484 /// GlobalVar '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
485 /// ... -> global variable
481486 bool LLParser::ParseNamedGlobal() {
482487 assert(Lex.getKind() == lltok::GlobalVar);
483488 LocTy NameLoc = Lex.getLoc();
485490 Lex.Lex();
486491
487492 bool HasLinkage;
488 unsigned Linkage, Visibility;
493 unsigned Linkage, Visibility, DLLStorageClass;
489494 if (ParseToken(lltok::equal, "expected '=' in global variable") ||
490495 ParseOptionalLinkage(Linkage, HasLinkage) ||
491 ParseOptionalVisibility(Visibility))
496 ParseOptionalVisibility(Visibility) ||
497 ParseOptionalDLLStorageClass(DLLStorageClass))
492498 return true;
493499
494500 if (HasLinkage || Lex.getKind() != lltok::kw_alias)
495 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
496 return ParseAlias(Name, NameLoc, Visibility);
501 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
502 DLLStorageClass);
503 return ParseAlias(Name, NameLoc, Visibility, DLLStorageClass);
497504 }
498505
499506 // MDString:
614621 }
615622
616623 /// ParseAlias:
617 /// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee
624 /// ::= GlobalVar '=' OptionalVisibility OptionalDLLStorageClass 'alias'
625 /// OptionalLinkage Aliasee
618626 /// Aliasee
619627 /// ::= TypeAndValue
620628 /// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
621629 /// ::= 'getelementptr' 'inbounds'? '(' ... ')'
622630 ///
623 /// Everything through visibility has already been parsed.
631 /// Everything through DLL storage class has already been parsed.
624632 ///
625633 bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
626 unsigned Visibility) {
634 unsigned Visibility, unsigned DLLStorageClass) {
627635 assert(Lex.getKind() == lltok::kw_alias);
628636 Lex.Lex();
629637 LocTy LinkageLoc = Lex.getLoc();
658666 (GlobalValue::LinkageTypes)Linkage, Name,
659667 Aliasee);
660668 GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
669 GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
661670
662671 // See if this value already exists in the symbol table. If so, it is either
663672 // a redefinition or a definition of a forward reference.
690699 }
691700
692701 /// ParseGlobal
693 /// ::= GlobalVar '=' OptionalLinkage OptionalVisibility OptionalThreadLocal
694 /// OptionalAddrSpace OptionalUnNammedAddr
702 /// ::= GlobalVar '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
703 /// OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
695704 /// OptionalExternallyInitialized GlobalType Type Const
696 /// ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
697 /// OptionalAddrSpace OptionalUnNammedAddr
705 /// ::= OptionalLinkage OptionalVisibility OptionalDLLStorageClass
706 /// OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
698707 /// OptionalExternallyInitialized GlobalType Type Const
699708 ///
700709 /// Everything through visibility has been parsed already.
701710 ///
702711 bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
703712 unsigned Linkage, bool HasLinkage,
704 unsigned Visibility) {
713 unsigned Visibility, unsigned DLLStorageClass) {
705714 unsigned AddrSpace;
706715 bool IsConstant, UnnamedAddr, IsExternallyInitialized;
707716 GlobalVariable::ThreadLocalMode TLM;
724733 // If the linkage is specified and is external, then no initializer is
725734 // present.
726735 Constant *Init = 0;
727 if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage &&
728 Linkage != GlobalValue::ExternalWeakLinkage &&
736 if (!HasLinkage || (Linkage != GlobalValue::ExternalWeakLinkage &&
729737 Linkage != GlobalValue::ExternalLinkage)) {
730738 if (ParseGlobalValue(Ty, Init))
731739 return true;
774782 GV->setConstant(IsConstant);
775783 GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
776784 GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
785 GV->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
777786 GV->setExternallyInitialized(IsExternallyInitialized);
778787 GV->setThreadLocalMode(TLM);
779788 GV->setUnnamedAddr(UnnamedAddr);
12761285 /// ::= 'linkonce_odr'
12771286 /// ::= 'available_externally'
12781287 /// ::= 'appending'
1279 /// ::= 'dllexport'
12801288 /// ::= 'common'
1281 /// ::= 'dllimport'
12821289 /// ::= 'extern_weak'
12831290 /// ::= 'external'
12841291 bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
12991306 Res = GlobalValue::AvailableExternallyLinkage;
13001307 break;
13011308 case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
1302 case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
13031309 case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
1304 case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
13051310 case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
13061311 case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
13071312 }
13221327 case lltok::kw_default: Res = GlobalValue::DefaultVisibility; break;
13231328 case lltok::kw_hidden: Res = GlobalValue::HiddenVisibility; break;
13241329 case lltok::kw_protected: Res = GlobalValue::ProtectedVisibility; break;
1330 }
1331 Lex.Lex();
1332 return false;
1333 }
1334
1335 /// ParseOptionalDLLStorageClass
1336 /// ::= /*empty*/
1337 /// ::= 'dllimport'
1338 /// ::= 'dllexport'
1339 ///
1340 bool LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
1341 switch (Lex.getKind()) {
1342 default: Res = GlobalValue::DefaultStorageClass; return false;
1343 case lltok::kw_dllimport: Res = GlobalValue::DLLImportStorageClass; break;
1344 case lltok::kw_dllexport: Res = GlobalValue::DLLExportStorageClass; break;
13251345 }
13261346 Lex.Lex();
13271347 return false;
29332953 unsigned Linkage;
29342954
29352955 unsigned Visibility;
2956 unsigned DLLStorageClass;
29362957 AttrBuilder RetAttrs;
29372958 CallingConv::ID CC;
29382959 Type *RetType = 0;
29392960 LocTy RetTypeLoc = Lex.getLoc();
29402961 if (ParseOptionalLinkage(Linkage) ||
29412962 ParseOptionalVisibility(Visibility) ||
2963 ParseOptionalDLLStorageClass(DLLStorageClass) ||
29422964 ParseOptionalCallingConv(CC) ||
29432965 ParseOptionalReturnAttrs(RetAttrs) ||
29442966 ParseType(RetType, RetTypeLoc, true /*void allowed*/))
29482970 switch ((GlobalValue::LinkageTypes)Linkage) {
29492971 case GlobalValue::ExternalLinkage:
29502972 break; // always ok.
2951 case GlobalValue::DLLImportLinkage:
29522973 case GlobalValue::ExternalWeakLinkage:
29532974 if (isDefine)
29542975 return Error(LinkageLoc, "invalid linkage for function definition");
29622983 case GlobalValue::LinkOnceODRLinkage:
29632984 case GlobalValue::WeakAnyLinkage:
29642985 case GlobalValue::WeakODRLinkage:
2965 case GlobalValue::DLLExportLinkage:
29662986 if (!isDefine)
29672987 return Error(LinkageLoc, "invalid linkage for function declaration");
29682988 break;
31093129
31103130 Fn->setLinkage((GlobalValue::LinkageTypes)Linkage);
31113131 Fn->setVisibility((GlobalValue::VisibilityTypes)Visibility);
3132 Fn->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
31123133 Fn->setCallingConv(CC);
31133134 Fn->setAttributes(PAL);
31143135 Fn->setUnnamedAddr(UnnamedAddr);
203203 bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
204204 }
205205 bool ParseOptionalVisibility(unsigned &Visibility);
206 bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
206207 bool ParseOptionalCallingConv(CallingConv::ID &CC);
207208 bool ParseOptionalAlignment(unsigned &Alignment);
208209 bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
233234 bool ParseUnnamedGlobal();
234235 bool ParseNamedGlobal();
235236 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
236 bool HasLinkage, unsigned Visibility);
237 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
237 bool HasLinkage, unsigned Visibility,
238 unsigned DLLStorageClass);
239 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility,
240 unsigned DLLStorageClass);
238241 bool ParseStandaloneMetadata();
239242 bool ParseNamedMetadata();
240243 bool ParseMDString(MDString *&Result);
7979 case 2: return GlobalValue::AppendingLinkage;
8080 case 3: return GlobalValue::InternalLinkage;
8181 case 4: return GlobalValue::LinkOnceAnyLinkage;
82 case 5: return GlobalValue::DLLImportLinkage;
83 case 6: return GlobalValue::DLLExportLinkage;
82 case 5: return GlobalValue::ExternalLinkage; // Obsolete DLLImportLinkage
83 case 6: return GlobalValue::ExternalLinkage; // Obsolete DLLExportLinkage
8484 case 7: return GlobalValue::ExternalWeakLinkage;
8585 case 8: return GlobalValue::CommonLinkage;
8686 case 9: return GlobalValue::PrivateLinkage;
9898 case 0: return GlobalValue::DefaultVisibility;
9999 case 1: return GlobalValue::HiddenVisibility;
100100 case 2: return GlobalValue::ProtectedVisibility;
101 }
102 }
103
104 static GlobalValue::DLLStorageClassTypes
105 GetDecodedDLLStorageClass(unsigned Val) {
106 switch (Val) {
107 default: // Map unknown values to default.
108 case 0: return GlobalValue::DefaultStorageClass;
109 case 1: return GlobalValue::DLLImportStorageClass;
110 case 2: return GlobalValue::DLLExportStorageClass;
101111 }
102112 }
103113
189199 case bitc::SYNCHSCOPE_SINGLETHREAD: return SingleThread;
190200 default: // Map unknown scopes to cross-thread.
191201 case bitc::SYNCHSCOPE_CROSSTHREAD: return CrossThread;
202 }
203 }
204
205 static void UpgradeDLLImportExportLinkage(llvm::GlobalValue *GV, unsigned Val) {
206 switch (Val) {
207 case 5: GV->setDLLStorageClass(GlobalValue::DLLImportStorageClass); break;
208 case 6: GV->setDLLStorageClass(GlobalValue::DLLExportStorageClass); break;
192209 }
193210 }
194211
17961813 }
17971814 // GLOBALVAR: [pointer type, isconst, initid,
17981815 // linkage, alignment, section, visibility, threadlocal,
1799 // unnamed_addr]
1816 // unnamed_addr, dllstorageclass]
18001817 case bitc::MODULE_CODE_GLOBALVAR: {
18011818 if (Record.size() < 6)
18021819 return Error(InvalidRecord);
18421859 NewGV->setVisibility(Visibility);
18431860 NewGV->setUnnamedAddr(UnnamedAddr);
18441861
1862 if (Record.size() > 10)
1863 NewGV->setDLLStorageClass(GetDecodedDLLStorageClass(Record[10]));
1864 else
1865 UpgradeDLLImportExportLinkage(NewGV, Record[3]);
1866
18451867 ValueList.push_back(NewGV);
18461868
18471869 // Remember which value to use for the global initializer.
18501872 break;
18511873 }
18521874 // FUNCTION: [type, callingconv, isproto, linkage, paramattr,
1853 // alignment, section, visibility, gc, unnamed_addr]
1875 // alignment, section, visibility, gc, unnamed_addr,
1876 // dllstorageclass]
18541877 case bitc::MODULE_CODE_FUNCTION: {
18551878 if (Record.size() < 8)
18561879 return Error(InvalidRecord);
18901913 Func->setUnnamedAddr(UnnamedAddr);
18911914 if (Record.size() > 10 && Record[10] != 0)
18921915 FunctionPrefixes.push_back(std::make_pair(Func, Record[10]-1));
1916
1917 if (Record.size() > 11)
1918 Func->setDLLStorageClass(GetDecodedDLLStorageClass(Record[11]));
1919 else
1920 UpgradeDLLImportExportLinkage(Func, Record[3]);
1921
18931922 ValueList.push_back(Func);
18941923
18951924 // If this is a function with a body, remember the prototype we are
19011930 break;
19021931 }
19031932 // ALIAS: [alias type, aliasee val#, linkage]
1904 // ALIAS: [alias type, aliasee val#, linkage, visibility]
1933 // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
19051934 case bitc::MODULE_CODE_ALIAS: {
19061935 if (Record.size() < 3)
19071936 return Error(InvalidRecord);
19161945 // Old bitcode files didn't have visibility field.
19171946 if (Record.size() > 3)
19181947 NewGA->setVisibility(GetDecodedVisibility(Record[3]));
1948 if (Record.size() > 4)
1949 NewGA->setDLLStorageClass(GetDecodedDLLStorageClass(Record[4]));
1950 else
1951 UpgradeDLLImportExportLinkage(NewGA, Record[2]);
19191952 ValueList.push_back(NewGA);
19201953 AliasInits.push_back(std::make_pair(NewGA, Record[1]));
19211954 break;
480480 case GlobalValue::AppendingLinkage: return 2;
481481 case GlobalValue::InternalLinkage: return 3;
482482 case GlobalValue::LinkOnceAnyLinkage: return 4;
483 case GlobalValue::DLLImportLinkage: return 5;
484 case GlobalValue::DLLExportLinkage: return 6;
485483 case GlobalValue::ExternalWeakLinkage: return 7;
486484 case GlobalValue::CommonLinkage: return 8;
487485 case GlobalValue::PrivateLinkage: return 9;
501499 case GlobalValue::ProtectedVisibility: return 2;
502500 }
503501 llvm_unreachable("Invalid visibility");
502 }
503
504 static unsigned getEncodedDLLStorageClass(const GlobalValue *GV) {
505 switch (GV->getDLLStorageClass()) {
506 case GlobalValue::DefaultStorageClass: return 0;
507 case GlobalValue::DLLImportStorageClass: return 1;
508 case GlobalValue::DLLExportStorageClass: return 2;
509 }
510 llvm_unreachable("Invalid DLL storage class");
504511 }
505512
506513 static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) {
606613
607614 // GLOBALVAR: [type, isconst, initid,
608615 // linkage, alignment, section, visibility, threadlocal,
609 // unnamed_addr, externally_initialized]
616 // unnamed_addr, externally_initialized, dllstorageclass]
610617 Vals.push_back(VE.getTypeID(GV->getType()));
611618 Vals.push_back(GV->isConstant());
612619 Vals.push_back(GV->isDeclaration() ? 0 :
616623 Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
617624 if (GV->isThreadLocal() ||
618625 GV->getVisibility() != GlobalValue::DefaultVisibility ||
619 GV->hasUnnamedAddr() || GV->isExternallyInitialized()) {
626 GV->hasUnnamedAddr() || GV->isExternallyInitialized() ||
627 GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
620628 Vals.push_back(getEncodedVisibility(GV));
621629 Vals.push_back(getEncodedThreadLocalMode(GV));
622630 Vals.push_back(GV->hasUnnamedAddr());
623631 Vals.push_back(GV->isExternallyInitialized());
632 Vals.push_back(getEncodedDLLStorageClass(GV));
624633 } else {
625634 AbbrevToUse = SimpleGVarAbbrev;
626635 }
645654 Vals.push_back(F->hasUnnamedAddr());
646655 Vals.push_back(F->hasPrefixData() ? (VE.getValueID(F->getPrefixData()) + 1)
647656 : 0);
657 Vals.push_back(getEncodedDLLStorageClass(F));
648658
649659 unsigned AbbrevToUse = 0;
650660 Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
659669 Vals.push_back(VE.getValueID(AI->getAliasee()));
660670 Vals.push_back(getEncodedLinkage(AI));
661671 Vals.push_back(getEncodedVisibility(AI));
672 Vals.push_back(getEncodedDLLStorageClass(AI));
662673 unsigned AbbrevToUse = 0;
663674 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
664675 Vals.clear();
256256 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
257257 }
258258 return;
259 case GlobalValue::DLLExportLinkage:
260259 case GlobalValue::AppendingLinkage:
261260 // FIXME: appending linkage variables should go into a section of
262261 // their name or something. For now, just emit them as external.
271270 return;
272271 case GlobalValue::AvailableExternallyLinkage:
273272 llvm_unreachable("Should never emit this");
274 case GlobalValue::DLLImportLinkage:
275273 case GlobalValue::ExternalWeakLinkage:
276274 llvm_unreachable("Don't know how to emit these");
277275 }
12101210 }
12111211
12121212 // If the existing global is strong, never replace it.
1213 if (GVEntry->hasExternalLinkage() ||
1214 GVEntry->hasDLLImportLinkage() ||
1215 GVEntry->hasDLLExportLinkage())
1213 if (GVEntry->hasExternalLinkage())
12161214 continue;
12171215
12181216 // Otherwise, we know it's linkonce/weak, replace it if this is a strong
13661366 case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break;
13671367 case GlobalValue::CommonLinkage: Out << "common "; break;
13681368 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1369 case GlobalValue::DLLImportLinkage: Out << "dllimport "; break;
1370 case GlobalValue::DLLExportLinkage: Out << "dllexport "; break;
13711369 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
13721370 case GlobalValue::AvailableExternallyLinkage:
13731371 Out << "available_externally ";
13821380 case GlobalValue::DefaultVisibility: break;
13831381 case GlobalValue::HiddenVisibility: Out << "hidden "; break;
13841382 case GlobalValue::ProtectedVisibility: Out << "protected "; break;
1383 }
1384 }
1385
1386 static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT,
1387 formatted_raw_ostream &Out) {
1388 switch (SCT) {
1389 case GlobalValue::DefaultStorageClass: break;
1390 case GlobalValue::DLLImportStorageClass: Out << "dllimport "; break;
1391 case GlobalValue::DLLExportStorageClass: Out << "dllexport "; break;
13851392 }
13861393 }
13871394
14171424
14181425 PrintLinkage(GV->getLinkage(), Out);
14191426 PrintVisibility(GV->getVisibility(), Out);
1427 PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
14201428 PrintThreadLocalModel(GV->getThreadLocalMode(), Out);
14211429
14221430 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
14541462 Out << " = ";
14551463 }
14561464 PrintVisibility(GA->getVisibility(), Out);
1465 PrintDLLStorageClass(GA->getDLLStorageClass(), Out);
14571466
14581467 Out << "alias ";
14591468
15511560
15521561 PrintLinkage(F->getLinkage(), Out);
15531562 PrintVisibility(F->getVisibility(), Out);
1563 PrintDLLStorageClass(F->getDLLStorageClass(), Out);
15541564
15551565 // Print the calling convention.
15561566 if (F->getCallingConv() != CallingConv::C) {
11631163 return LLVMLinkerPrivateLinkage;
11641164 case GlobalValue::LinkerPrivateWeakLinkage:
11651165 return LLVMLinkerPrivateWeakLinkage;
1166 case GlobalValue::DLLImportLinkage:
1167 return LLVMDLLImportLinkage;
1168 case GlobalValue::DLLExportLinkage:
1169 return LLVMDLLExportLinkage;
11701166 case GlobalValue::ExternalWeakLinkage:
11711167 return LLVMExternalWeakLinkage;
11721168 case GlobalValue::CommonLinkage:
12181214 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
12191215 break;
12201216 case LLVMDLLImportLinkage:
1221 GV->setLinkage(GlobalValue::DLLImportLinkage);
1217 DEBUG(errs()
1218 << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
12221219 break;
12231220 case LLVMDLLExportLinkage:
1224 GV->setLinkage(GlobalValue::DLLExportLinkage);
1221 DEBUG(errs()
1222 << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
12251223 break;
12261224 case LLVMExternalWeakLinkage:
12271225 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
420420 Assert1(!GV.isDeclaration() ||
421421 GV.isMaterializable() ||
422422 GV.hasExternalLinkage() ||
423 GV.hasDLLImportLinkage() ||
424423 GV.hasExternalWeakLinkage() ||
425424 (isa(GV) &&
426425 (GV.hasLocalLinkage() || GV.hasWeakLinkage())),
427 "Global is external, but doesn't have external or dllimport or weak linkage!",
426 "Global is external, but doesn't have external or weak linkage!",
428427 &GV);
429
430 Assert1(!GV.hasDLLImportLinkage() || GV.isDeclaration(),
431 "Global is marked as dllimport, but not external", &GV);
432428
433429 Assert1(!GV.hasAppendingLinkage() || isa(GV),
434430 "Only global variables can have appending linkage!", &GV);
455451 &GV);
456452 }
457453 } else {
458 Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
459 GV.hasExternalWeakLinkage(),
454 Assert1(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),
460455 "invalid linkage type for global declaration", &GV);
461456 }
462457
500495 }
501496 }
502497 }
498
499 Assert1(!GV.hasDLLImportStorageClass() ||
500 (GV.isDeclaration() && GV.hasExternalLinkage()) ||
501 GV.hasAvailableExternallyLinkage(),
502 "Global is marked as dllimport, but not external", &GV);
503503
504504 if (!GV.hasInitializer()) {
505505 visitGlobalValue(GV);
10771077 if (F.isMaterializable()) {
10781078 // Function has a body somewhere we can't see.
10791079 } else if (F.isDeclaration()) {
1080 Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
1081 F.hasExternalWeakLinkage(),
1080 Assert1(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),
10821081 "invalid linkage type for function declaration", &F);
10831082 } else {
10841083 // Verify that this function (which has a body) is not named "llvm.*". It
11041103 if (F.hasAddressTaken(&U))
11051104 Assert1(0, "Invalid user of intrinsic instruction!", U);
11061105 }
1106
1107 Assert1(!F.hasDLLImportStorageClass() ||
1108 (F.isDeclaration() && F.hasExternalLinkage()) ||
1109 F.hasAvailableExternallyLinkage(),
1110 "Function is marked as dllimport, but not external.", &F);
11071111 }
11081112
11091113 // verifyBasicBlock - Verify that a basic block is well formed...
542542 if (SrcIsDeclaration) {
543543 // If Src is external or if both Src & Dest are external.. Just link the
544544 // external globals, we aren't adding anything.
545 if (Src->hasDLLImportLinkage()) {
546 // If one of GVs has DLLImport linkage, result should be dllimport'ed.
545 if (Src->hasDLLImportStorageClass()) {
546 // If one of GVs is marked as DLLImport, result should be dllimport'ed.
547547 if (DestIsDeclaration) {
548548 LinkFromSrc = true;
549549 LT = Src->getLinkage();
556556 LinkFromSrc = false;
557557 LT = Dest->getLinkage();
558558 }
559 } else if (DestIsDeclaration && !Dest->hasDLLImportLinkage()) {
559 } else if (DestIsDeclaration && !Dest->hasDLLImportStorageClass()) {
560560 // If Dest is external but Src is not:
561561 LinkFromSrc = true;
562562 LT = Src->getLinkage();
583583 LT = GlobalValue::ExternalLinkage;
584584 }
585585 } else {
586 assert((Dest->hasExternalLinkage() || Dest->hasDLLImportLinkage() ||
587 Dest->hasDLLExportLinkage() || Dest->hasExternalWeakLinkage()) &&
588 (Src->hasExternalLinkage() || Src->hasDLLImportLinkage() ||
589 Src->hasDLLExportLinkage() || Src->hasExternalWeakLinkage()) &&
586 assert((Dest->hasExternalLinkage() || Dest->hasExternalWeakLinkage()) &&
587 (Src->hasExternalLinkage() || Src->hasExternalWeakLinkage()) &&
590588 "Unexpected linkage type!");
591589 return emitError("Linking globals named '" + Src->getName() +
592590 "': symbol multiply defined!");
130130 private:
131131 void printLinkageType(GlobalValue::LinkageTypes LT);
132132 void printVisibilityType(GlobalValue::VisibilityTypes VisTypes);
133 void printDLLStorageClassType(GlobalValue::DLLStorageClassTypes DSCType);
133134 void printThreadLocalMode(GlobalVariable::ThreadLocalMode TLM);
134135 void printCallingConv(CallingConv::ID cc);
135136 void printEscapedString(const std::string& str);
299300 Out << "GlobalValue::AppendingLinkage"; break;
300301 case GlobalValue::ExternalLinkage:
301302 Out << "GlobalValue::ExternalLinkage"; break;
302 case GlobalValue::DLLImportLinkage:
303 Out << "GlobalValue::DLLImportLinkage"; break;
304 case GlobalValue::DLLExportLinkage:
305 Out << "GlobalValue::DLLExportLinkage"; break;
306303 case GlobalValue::ExternalWeakLinkage:
307304 Out << "GlobalValue::ExternalWeakLinkage"; break;
308305 case GlobalValue::CommonLinkage:
320317 break;
321318 case GlobalValue::ProtectedVisibility:
322319 Out << "GlobalValue::ProtectedVisibility";
320 break;
321 }
322 }
323
324 void CppWriter::printDLLStorageClassType(
325 GlobalValue::DLLStorageClassTypes DSCType) {
326 switch (DSCType) {
327 case GlobalValue::DefaultStorageClass:
328 Out << "GlobalValue::DefaultStorageClass";
329 break;
330 case GlobalValue::DLLImportStorageClass:
331 Out << "GlobalValue::DLLImportStorageClass";
332 break;
333 case GlobalValue::DLLExportStorageClass:
334 Out << "GlobalValue::DLLExportStorageClass";
323335 break;
324336 }
325337 }
10271039 Out << ");";
10281040 nl(Out);
10291041 }
1042 if (GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
1043 printCppName(GV);
1044 Out << "->setDLLStorageClass(";
1045 printDLLStorageClassType(GV->getDLLStorageClass());
1046 Out << ");";
1047 nl(Out);
1048 }
10301049 if (GV->isThreadLocal()) {
10311050 printCppName(GV);
10321051 Out << "->setThreadLocalMode(";
17451764 Out << ");";
17461765 nl(Out);
17471766 }
1767 if (F->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
1768 printCppName(F);
1769 Out << "->setDLLStorageClass(";
1770 printDLLStorageClassType(F->getDLLStorageClass());
1771 Out << ");";
1772 nl(Out);
1773 }
17481774 if (F->hasGC()) {
17491775 printCppName(F);
17501776 Out << "->setGC(\"" << F->getGC() << "\");";
648648 // Necessary for dllexport support
649649 std::vector DLLExportedFns, DLLExportedGlobals;
650650
651 const TargetLoweringObjectFileCOFF &TLOFCOFF =
652 static_cast(getObjFileLowering());
653
654651 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
655 if (I->hasDLLExportLinkage())
652 if (I->hasDLLExportStorageClass())
656653 DLLExportedFns.push_back(getSymbol(I));
657654
658655 for (Module::const_global_iterator I = M.global_begin(),
659656 E = M.global_end(); I != E; ++I)
660 if (I->hasDLLExportLinkage())
657 if (I->hasDLLExportStorageClass())
661658 DLLExportedGlobals.push_back(getSymbol(I));
662659
663660 // Output linker support code for dllexported globals on windows.
664661 if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) {
662 const TargetLoweringObjectFileCOFF &TLOFCOFF =
663 static_cast(getObjFileLowering());
664
665665 OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());
666666 SmallString<128> name;
667667 for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) {
696696 return false;
697697
698698 // Can't handle DLLImport.
699 if (GV->hasDLLImportLinkage())
699 if (GV->hasDLLImportStorageClass())
700700 return false;
701701
702702 // Can't handle TLS.
27952795 // We should use extra load for direct calls to dllimported functions in
27962796 // non-JIT mode.
27972797 const GlobalValue *GV = G->getGlobal();
2798 if (!GV->hasDLLImportLinkage()) {
2798 if (!GV->hasDLLImportStorageClass()) {
27992799 unsigned char OpFlags = 0;
28002800 bool ExtraLoad = false;
28012801 unsigned WrapperKind = ISD::DELETED_NODE;
5454 ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
5555 // DLLImport only exists on windows, it is implemented as a load from a
5656 // DLLIMPORT stub.
57 if (GV->hasDLLImportLinkage())
57 if (GV->hasDLLImportStorageClass())
5858 return X86II::MO_DLLIMPORT;
5959
6060 // Determine whether this is a reference to a definition or a declaration.
134134 case GlobalValue::InternalLinkage:
135135 case GlobalValue::PrivateLinkage:
136136 break;
137 case GlobalValue::DLLImportLinkage:
138 llvm_unreachable("DLLImport linkage is not supported by this target!");
139 case GlobalValue::DLLExportLinkage:
140 llvm_unreachable("DLLExport linkage is not supported by this target!");
141137 default:
142138 llvm_unreachable("Unknown linkage type!");
143139 }
115115 return false;
116116
117117 // Assume that dllexported symbols are referenced elsewhere
118 if (GV.hasDLLExportLinkage())
118 if (GV.hasDLLExportStorageClass())
119119 return false;
120120
121121 // Already has internal linkage
4949 ; CHECK: @dllexport.var = dllexport global i32 0
5050
5151 @dllimport.var = dllimport global i32
52 ; CHECK: @dllimport.var = dllimport global i32
52 ; CHECK: @dllimport.var = external dllimport global i32
5353
5454 define private void @private()
5555 ; CHECK: define private void @private
+0
-14
test/CodeGen/X86/dll-linkage.ll less more
None ; RUN: llc < %s -mtriple=i386-pc-mingw32 | FileCheck %s
1
2 ; RUN: llc < %s -mtriple=i386-pc-mingw32 -O0 | FileCheck %s -check-prefix=FAST
3 ; PR6275
4
5 declare dllimport void @foo()
6
7 define void @bar() nounwind {
8 ; CHECK: calll *__imp__foo
9 ; FAST: movl __imp__foo, [[R:%[a-z]{3}]]
10 ; FAST: calll *[[R]]
11 call void @foo()
12 ret void
13 }
0 ; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
1 ; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck -check-prefix=CHECK -check-prefix=MINGW %s
2
3 ; CHECK: .text
4
5 define void @notExported() {
6 ret void
7 }
8
9 ; CHECK: .globl f1
10 define dllexport void @f1() {
11 ret void
12 }
13
14 ; CHECK: .globl f2
15 define dllexport void @f2() unnamed_addr {
16 ret void
17 }
18
19 ; CHECK: .section .text,"xr",discard,lnk1
20 ; CHECK: .globl lnk1
21 define linkonce_odr dllexport void @lnk1() {
22 ret void
23 }
24
25 ; CHECK: .section .text,"xr",discard,lnk2
26 ; CHECK: .globl lnk2
27 define linkonce_odr dllexport void @lnk2() alwaysinline {
28 ret void
29 }
30
31 ; CHECK: .section .text,"xr",discard,weak1
32 ; CHECK: .globl weak1
33 define weak_odr dllexport void @weak1() {
34 ret void
35 }
36
37
38 ; CHECK: .data
39 ; CHECK: .globl Var1
40 @Var1 = dllexport global i32 1, align 4
41
42 ; CHECK: .rdata,"r"
43 ; CHECK: .globl Var2
44 @Var2 = dllexport unnamed_addr constant i32 1
45
46 ; CHECK: .comm Var3
47 @Var3 = common dllexport global i32 0, align 4
48
49 ; CHECK: .section .data,"w",discard,WeakVar1
50 ; CHECK: .globl WeakVar1
51 @WeakVar1 = weak_odr dllexport global i32 1, align 4
52
53 ; CHECK: .section .rdata,"r",discard,WeakVar2
54 ; CHECK: .globl WeakVar2
55 @WeakVar2 = weak_odr dllexport unnamed_addr constant i32 1
56
57
58 ; CHECK: .section .drectve
59 ; WIN32: /EXPORT:Var1,DATA
60 ; WIN32: /EXPORT:Var2,DATA
61 ; WIN32: /EXPORT:Var3,DATA
62 ; WIN32: /EXPORT:WeakVar1,DATA
63 ; WIN32: /EXPORT:WeakVar2,DATA
64 ; WIN32: /EXPORT:f1
65 ; WIN32: /EXPORT:f2
66 ; WIN32: /EXPORT:lnk1
67 ; WIN32: /EXPORT:lnk2
68 ; WIN32: /EXPORT:weak1
69 ; MINGW: -export:Var1,data
70 ; MINGW: -export:Var2,data
71 ; MINGW: -export:Var3,data
72 ; MINGW: -export:WeakVar1,data
73 ; MINGW: -export:WeakVar2,data
74 ; MINGW: -export:f1
75 ; MINGW: -export:f2
76 ; MINGW: -export:lnk1
77 ; MINGW: -export:lnk2
78 ; MINGW: -export:weak1
None ; RUN: llc < %s | FileCheck %s
1 ; PR2936
0 ; RUN: llc -mtriple i386-pc-win32 < %s | FileCheck -check-prefix=CHECK -check-prefix=WIN32 %s
1 ; RUN: llc -mtriple i386-pc-mingw32 < %s | FileCheck -check-prefix=CHECK -check-prefix=MINGW %s
22
3 target triple = "i386-pc-mingw32"
3 ; CHECK: .text
44
5 define dllexport x86_fastcallcc i32 @foo() nounwind {
6 entry:
5 define void @notExported() {
6 ret void
7 }
8
9 ; CHECK: .globl _f1
10 define dllexport void @f1() {
11 ret void
12 }
13
14 ; CHECK: .globl _f2
15 define dllexport void @f2() unnamed_addr {
16 ret void
17 }
18
19 ; CHECK: .globl _stdfun@0
20 define dllexport x86_stdcallcc void @stdfun() nounwind {
21 ret void
22 }
23
24 ; CHECK: .globl @fastfun@0
25 define dllexport x86_fastcallcc i32 @fastfun() nounwind {
726 ret i32 0
827 }
928
29 ; CHECK: .globl _thisfun
30 define dllexport x86_thiscallcc void @thisfun() nounwind {
31 ret void
32 }
33
34 ; CHECK: .section .text,"xr",discard,_lnk1
35 ; CHECK: .globl _lnk1
36 define linkonce_odr dllexport void @lnk1() {
37 ret void
38 }
39
40 ; CHECK: .section .text,"xr",discard,_lnk2
41 ; CHECK: .globl _lnk2
42 define linkonce_odr dllexport void @lnk2() alwaysinline {
43 ret void
44 }
45
46 ; CHECK: .section .text,"xr",discard,_weak1
47 ; CHECK: .globl _weak1
48 define weak_odr dllexport void @weak1() {
49 ret void
50 }
51
52
53 ; CHECK: .data
54 ; CHECK: .globl _Var1
55 @Var1 = dllexport global i32 1, align 4
56
57 ; CHECK: .rdata,"r"
58 ; CHECK: .globl _Var2
59 @Var2 = dllexport unnamed_addr constant i32 1
60
61 ; CHECK: .comm _Var3
62 @Var3 = common dllexport global i32 0, align 4
63
64 ; CHECK: .section .data,"w",discard,_WeakVar1
65 ; CHECK: .globl _WeakVar1
66 @WeakVar1 = weak_odr dllexport global i32 1, align 4
67
68 ; CHECK: .section .rdata,"r",discard,_WeakVar2
69 ; CHECK: .globl _WeakVar2
70 @WeakVar2 = weak_odr dllexport unnamed_addr constant i32 1
71
72
1073 ; CHECK: .section .drectve
11 ; CHECK: -export:@foo@0
74 ; WIN32: /EXPORT:_Var1,DATA
75 ; WIN32: /EXPORT:_Var2,DATA
76 ; WIN32: /EXPORT:_Var3,DATA
77 ; WIN32: /EXPORT:_WeakVar1,DATA
78 ; WIN32: /EXPORT:_WeakVar2,DATA
79 ; WIN32: /EXPORT:_f1
80 ; WIN32: /EXPORT:_f2
81 ; WIN32: /EXPORT:_stdfun@0
82 ; WIN32: /EXPORT:@fastfun@0
83 ; WIN32: /EXPORT:_thisfun
84 ; WIN32: /EXPORT:_lnk1
85 ; WIN32: /EXPORT:_lnk2
86 ; WIN32: /EXPORT:_weak1
87 ; MINGW: -export:_Var1,data
88 ; MINGW: -export:_Var2,data
89 ; MINGW: -export:_Var3,data
90 ; MINGW: -export:_WeakVar1,data
91 ; MINGW: -export:_WeakVar2,data
92 ; MINGW: -export:_f1
93 ; MINGW: -export:_f2
94 ; MINGW: -export:_stdfun@0
95 ; MINGW: -export:@fastfun@0
96 ; MINGW: -export:_thisfun
97 ; MINGW: -export:_lnk1
98 ; MINGW: -export:_lnk2
99 ; MINGW: -export:_weak1
0 ; RUN: llc -mtriple x86_64-pc-win32 < %s | FileCheck %s
1 ; RUN: llc -mtriple x86_64-pc-mingw32 < %s | FileCheck %s
2 ;
3 ; RUN: llc -mtriple x86_64-pc-mingw32 -O0 < %s | FileCheck %s -check-prefix=FAST
4 ; PR6275
5 ;
6 ; RUN: opt -mtriple x86_64-pc-win32 -std-compile-opts -S < %s | FileCheck %s -check-prefix=OPT
7
8 @Var1 = external dllimport global i32
9 @Var2 = available_externally dllimport unnamed_addr constant i32 1
10
11 declare dllimport void @fun()
12
13 define available_externally dllimport void @inline1() {
14 ret void
15 }
16
17 define available_externally dllimport void @inline2() {
18 ret void
19 }
20
21 declare void @dummy(...)
22
23 define void @use() nounwind {
24 ; CHECK: callq *__imp_fun(%rip)
25 ; FAST: movq __imp_fun(%rip), [[R:%[a-z]{3}]]
26 ; FAST-NEXT: callq *[[R]]
27 call void @fun()
28
29 ; CHECK: callq *__imp_inline1(%rip)
30 ; CHECK: callq *__imp_inline2(%rip)
31 call void @inline1()
32 call void @inline2()
33
34 ; available_externally uses go away
35 ; OPT-NOT: call void @inline1()
36 ; OPT-NOT: call void @inline2()
37 ; OPT-NOT: load i32* @Var2
38 ; OPT: call void (...)* @dummy(i32 %1, i32 1)
39
40 ; CHECK-DAG: movq __imp_Var1(%rip), [[R1:%[a-z]{3}]]
41 ; CHECK-DAG: movq __imp_Var2(%rip), [[R2:%[a-z]{3}]]
42 %1 = load i32* @Var1
43 %2 = load i32* @Var2
44 call void(...)* @dummy(i32 %1, i32 %2)
45
46 ret void
47 }
0 ; RUN: llc -mtriple i386-pc-win32 < %s | FileCheck %s
1 ; RUN: llc -mtriple i386-pc-mingw32 < %s | FileCheck %s
2 ;
3 ; RUN: llc -mtriple i386-pc-mingw32 -O0 < %s | FileCheck %s -check-prefix=FAST
4 ; PR6275
5 ;
6 ; RUN: opt -mtriple i386-pc-win32 -std-compile-opts -S < %s | FileCheck %s -check-prefix=OPT
7
8 @Var1 = external dllimport global i32
9 @Var2 = available_externally dllimport unnamed_addr constant i32 1
10
11 declare dllimport void @fun()
12
13 define available_externally dllimport void @inline1() {
14 ret void
15 }
16
17 define available_externally dllimport void @inline2() alwaysinline {
18 ret void
19 }
20
21 declare dllimport x86_stdcallcc void @stdfun() nounwind
22 declare dllimport x86_fastcallcc void @fastfun() nounwind
23 declare dllimport x86_thiscallcc void @thisfun() nounwind
24
25 declare void @dummy(...)
26
27 define void @use() nounwind {
28 ; CHECK: calll *__imp__fun
29 ; FAST: movl __imp__fun, [[R:%[a-z]{3}]]
30 ; FAST-NEXT: calll *[[R]]
31 call void @fun()
32
33 ; CHECK: calll *__imp__inline1
34 ; CHECK: calll *__imp__inline2
35 call void @inline1()
36 call void @inline2()
37
38 ; CHECK: calll *__imp__stdfun@0
39 ; CHECK: calll *__imp_@fastfun@0
40 ; CHECK: calll *__imp__thisfun
41 call void @stdfun()
42 call void @fastfun()
43 call void @thisfun()
44
45 ; available_externally uses go away
46 ; OPT-NOT: call void @inline1()
47 ; OPT-NOT: call void @inline2()
48 ; OPT-NOT: load i32* @Var2
49 ; OPT: call void (...)* @dummy(i32 %1, i32 1)
50
51 ; CHECK-DAG: movl __imp__Var1, [[R1:%[a-z]{3}]]
52 ; CHECK-DAG: movl __imp__Var2, [[R2:%[a-z]{3}]]
53 %1 = load i32* @Var1
54 %2 = load i32* @Var2
55 call void(...)* @dummy(i32 %1, i32 %2)
56
57 ret void
58 }