llvm.org GIT mirror llvm / 55463f4
Revert "Decouple dllexport/dllimport from linkage" Revert this for now until I fix an issue in Clang with it. This reverts commit r199204. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199207 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Rieck 6 years ago
27 changed file(s) with 157 addition(s) and 547 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, dllstorageclass]``
660 ``[GLOBALVAR, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr]``
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
723715 .. _FUNCTION:
724716
725717 MODULE_CODE_FUNCTION Record
726718 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
727719
728 ``[FUNCTION, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prefix, dllstorageclass]``
720 ``[FUNCTION, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prefix]``
729721
730722 The ``FUNCTION`` record (code 8) marks the declaration or definition of a
731723 function. The operand fields are:
769761 * *prefix*: If non-zero, the value index of the prefix data for this function,
770762 plus 1.
771763
772 * *dllstorageclass*: An encoding of the `dllstorageclass`_ of this function
773
774764 MODULE_CODE_ALIAS Record
775765 ^^^^^^^^^^^^^^^^^^^^^^^^
776766
777 ``[ALIAS, alias type, aliasee val#, linkage, visibility, dllstorageclass]``
767 ``[ALIAS, alias type, aliasee val#, linkage, visibility]``
778768
779769 The ``ALIAS`` record (code 9) marks the definition of an alias. The operand
780770 fields are
786776 * *linkage*: An encoding of the `linkage type`_ for this alias
787777
788778 * *visibility*: If present, an encoding of the `visibility`_ of the alias
789
790 * *dllstorageclass*: If present, an encoding of the `dllstorageclass`_ of the alias
791779
792780 MODULE_CODE_PURGEVALS Record
793781 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
276295 It is illegal for a function *declaration* to have any linkage type
277 other than ``external`` or ``extern_weak``.
296 other than ``external``, ``dllimport`` or ``extern_weak``.
278297
279298 .. _callingconv:
280299
396415
397416 .. _namedtypes:
398417
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
540531 For example, the following defines a global in a numbered address space
541532 with an initializer, section, and alignment:
542533
564555
565556 LLVM function definitions consist of the "``define``" keyword, an
566557 optional :ref:`linkage type `, an optional :ref:`visibility
567 style `, an optional :ref:`DLL storage class `,
568 an optional :ref:`calling convention `,
558 style `, an optional :ref:`calling convention `,
569559 an optional ``unnamed_addr`` attribute, a return type, an optional
570560 :ref:`parameter attribute ` for the return type, a function
571561 name, a (possibly empty) argument list (each with optional :ref:`parameter
576566
577567 LLVM function declarations consist of the "``declare``" keyword, an
578568 optional :ref:`linkage type `, an optional :ref:`visibility
579 style `, an optional :ref:`DLL storage class `,
580 an optional :ref:`calling convention `,
569 style `, an optional :ref:`calling convention `,
581570 an optional ``unnamed_addr`` attribute, a return type, an optional
582571 :ref:`parameter attribute ` for the return type, a function
583572 name, a possibly empty list of arguments, an optional alignment, an optional
613602
614603 Syntax::
615604
616 define [linkage] [visibility] [DLLStorageClass]
605 define [linkage] [visibility]
617606 [cconv] [ret attrs]
618607 @ ([argument list])
619608 [fn Attrs] [section "name"] [align N]
626615
627616 Aliases act as "second name" for the aliasee value (which can be either
628617 function, global variable, another alias or bitcast of global value).
629 Aliases may have an optional :ref:`linkage type `, an optional
630 :ref:`visibility style `, and an optional :ref:`DLL storage class
631 `.
618 Aliases may have an optional :ref:`linkage type `, and an optional
619 :ref:`visibility style `.
632620
633621 Syntax::
634622
635 @ = [Visibility] [DLLStorageClass] alias [Linkage] @
623 @ = alias [Linkage] [Visibility] @
636624
637625 The linkage must be one of ``private``, ``linker_private``,
638626 ``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.
4446 ExternalWeakLinkage,///< ExternalWeak linkage description.
4547 CommonLinkage ///< Tentative definitions.
4648 };
5254 ProtectedVisibility ///< The GV is protected
5355 };
5456
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
6257 protected:
6358 GlobalValue(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps,
6459 LinkageTypes linkage, const Twine &Name)
6560 : Constant(ty, vty, Ops, NumOps), Linkage(linkage),
66 Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0),
67 DllStorageClass(DefaultStorageClass), Parent(0) {
61 Visibility(DefaultVisibility), Alignment(0), UnnamedAddr(0), Parent(0) {
6862 setName(Name);
6963 }
7064
7468 unsigned Visibility : 2; // The visibility style of this global
7569 unsigned Alignment : 16; // Alignment of this symbol, must be power of two
7670 unsigned UnnamedAddr : 1; // This value's address is not significant
77 unsigned DllStorageClass : 2; // DLL storage class
7871 Module *Parent; // The containing module.
7972 std::string Section; // Section to emit this into, empty mean default
8073 public:
9790 return Visibility == ProtectedVisibility;
9891 }
9992 void setVisibility(VisibilityTypes V) { Visibility = V; }
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
93
11294 bool hasSection() const { return !Section.empty(); }
11395 const std::string &getSection() const { return Section; }
11496 void setSection(StringRef S) { Section = S; }
162144 static bool isLocalLinkage(LinkageTypes Linkage) {
163145 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
164146 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;
165153 }
166154 static bool isExternalWeakLinkage(LinkageTypes Linkage) {
167155 return Linkage == ExternalWeakLinkage;
220208 return isLinkerPrivateWeakLinkage(Linkage);
221209 }
222210 bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
211 bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
212 bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
223213 bool hasExternalWeakLinkage() const { return isExternalWeakLinkage(Linkage); }
224214 bool hasCommonLinkage() const { return isCommonLinkage(Linkage); }
225215
283283 LLVMInternalLinkage, /**< Rename collisions when linking (static
284284 functions) */
285285 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
286 LLVMDLLImportLinkage, /**< Obsolete */
287 LLVMDLLExportLinkage, /**< Obsolete */
286 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
287 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
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 OptionalDLLStorageClass
245 // OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
244 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
245 // 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
256257 case lltok::kw_common: // OptionalLinkage
258 case lltok::kw_dllimport: // OptionalLinkage
257259 case lltok::kw_extern_weak: // OptionalLinkage
258260 case lltok::kw_external: { // OptionalLinkage
259 unsigned Linkage, Visibility, DLLStorageClass;
261 unsigned Linkage, Visibility;
260262 if (ParseOptionalLinkage(Linkage) ||
261263 ParseOptionalVisibility(Visibility) ||
262 ParseOptionalDLLStorageClass(DLLStorageClass) ||
263 ParseGlobal("", SMLoc(), Linkage, true, Visibility, DLLStorageClass))
264 ParseGlobal("", SMLoc(), Linkage, true, Visibility))
264265 return true;
265266 break;
266267 }
267268 case lltok::kw_default: // OptionalVisibility
268269 case lltok::kw_hidden: // OptionalVisibility
269270 case lltok::kw_protected: { // OptionalVisibility
270 unsigned Visibility, DLLStorageClass;
271 unsigned Visibility;
271272 if (ParseOptionalVisibility(Visibility) ||
272 ParseOptionalDLLStorageClass(DLLStorageClass) ||
273 ParseGlobal("", SMLoc(), 0, false, Visibility, DLLStorageClass))
273 ParseGlobal("", SMLoc(), 0, false, Visibility))
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, 0)) return true;
282 if (ParseGlobal("", SMLoc(), 0, false, 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 OptionalDLLStorageClass
449 /// ... -> global variable
448 /// OptionalLinkage OptionalVisibility ... -> global variable
450449 /// GlobalID '=' OptionalVisibility ALIAS ...
451 /// GlobalID '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
452 /// ... -> global variable
450 /// GlobalID '=' OptionalLinkage OptionalVisibility ... -> global variable
453451 bool LLParser::ParseUnnamedGlobal() {
454452 unsigned VarID = NumberedVals.size();
455453 std::string Name;
467465 }
468466
469467 bool HasLinkage;
470 unsigned Linkage, Visibility, DLLStorageClass;
468 unsigned Linkage, Visibility;
471469 if (ParseOptionalLinkage(Linkage, HasLinkage) ||
472 ParseOptionalVisibility(Visibility) ||
473 ParseOptionalDLLStorageClass(DLLStorageClass))
470 ParseOptionalVisibility(Visibility))
474471 return true;
475472
476473 if (HasLinkage || Lex.getKind() != lltok::kw_alias)
477 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
478 DLLStorageClass);
479 return ParseAlias(Name, NameLoc, Visibility, DLLStorageClass);
474 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
475 return ParseAlias(Name, NameLoc, Visibility);
480476 }
481477
482478 /// ParseNamedGlobal:
483479 /// GlobalVar '=' OptionalVisibility ALIAS ...
484 /// GlobalVar '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
485 /// ... -> global variable
480 /// GlobalVar '=' OptionalLinkage OptionalVisibility ... -> global variable
486481 bool LLParser::ParseNamedGlobal() {
487482 assert(Lex.getKind() == lltok::GlobalVar);
488483 LocTy NameLoc = Lex.getLoc();
490485 Lex.Lex();
491486
492487 bool HasLinkage;
493 unsigned Linkage, Visibility, DLLStorageClass;
488 unsigned Linkage, Visibility;
494489 if (ParseToken(lltok::equal, "expected '=' in global variable") ||
495490 ParseOptionalLinkage(Linkage, HasLinkage) ||
496 ParseOptionalVisibility(Visibility) ||
497 ParseOptionalDLLStorageClass(DLLStorageClass))
491 ParseOptionalVisibility(Visibility))
498492 return true;
499493
500494 if (HasLinkage || Lex.getKind() != lltok::kw_alias)
501 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
502 DLLStorageClass);
503 return ParseAlias(Name, NameLoc, Visibility, DLLStorageClass);
495 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
496 return ParseAlias(Name, NameLoc, Visibility);
504497 }
505498
506499 // MDString:
621614 }
622615
623616 /// ParseAlias:
624 /// ::= GlobalVar '=' OptionalVisibility OptionalDLLStorageClass 'alias'
625 /// OptionalLinkage Aliasee
617 /// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee
626618 /// Aliasee
627619 /// ::= TypeAndValue
628620 /// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
629621 /// ::= 'getelementptr' 'inbounds'? '(' ... ')'
630622 ///
631 /// Everything through DLL storage class has already been parsed.
623 /// Everything through visibility has already been parsed.
632624 ///
633625 bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
634 unsigned Visibility, unsigned DLLStorageClass) {
626 unsigned Visibility) {
635627 assert(Lex.getKind() == lltok::kw_alias);
636628 Lex.Lex();
637629 LocTy LinkageLoc = Lex.getLoc();
666658 (GlobalValue::LinkageTypes)Linkage, Name,
667659 Aliasee);
668660 GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
669 GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
670661
671662 // See if this value already exists in the symbol table. If so, it is either
672663 // a redefinition or a definition of a forward reference.
699690 }
700691
701692 /// ParseGlobal
702 /// ::= GlobalVar '=' OptionalLinkage OptionalVisibility OptionalDLLStorageClass
703 /// OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
693 /// ::= GlobalVar '=' OptionalLinkage OptionalVisibility OptionalThreadLocal
694 /// OptionalAddrSpace OptionalUnNammedAddr
704695 /// OptionalExternallyInitialized GlobalType Type Const
705 /// ::= OptionalLinkage OptionalVisibility OptionalDLLStorageClass
706 /// OptionalThreadLocal OptionalAddrSpace OptionalUnNammedAddr
696 /// ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
697 /// OptionalAddrSpace OptionalUnNammedAddr
707698 /// OptionalExternallyInitialized GlobalType Type Const
708699 ///
709700 /// Everything through visibility has been parsed already.
710701 ///
711702 bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
712703 unsigned Linkage, bool HasLinkage,
713 unsigned Visibility, unsigned DLLStorageClass) {
704 unsigned Visibility) {
714705 unsigned AddrSpace;
715706 bool IsConstant, UnnamedAddr, IsExternallyInitialized;
716707 GlobalVariable::ThreadLocalMode TLM;
733724 // If the linkage is specified and is external, then no initializer is
734725 // present.
735726 Constant *Init = 0;
736 if (!HasLinkage || (Linkage != GlobalValue::ExternalWeakLinkage &&
727 if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage &&
728 Linkage != GlobalValue::ExternalWeakLinkage &&
737729 Linkage != GlobalValue::ExternalLinkage)) {
738730 if (ParseGlobalValue(Ty, Init))
739731 return true;
782774 GV->setConstant(IsConstant);
783775 GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
784776 GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
785 GV->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
786777 GV->setExternallyInitialized(IsExternallyInitialized);
787778 GV->setThreadLocalMode(TLM);
788779 GV->setUnnamedAddr(UnnamedAddr);
12851276 /// ::= 'linkonce_odr'
12861277 /// ::= 'available_externally'
12871278 /// ::= 'appending'
1279 /// ::= 'dllexport'
12881280 /// ::= 'common'
1281 /// ::= 'dllimport'
12891282 /// ::= 'extern_weak'
12901283 /// ::= 'external'
12911284 bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
13061299 Res = GlobalValue::AvailableExternallyLinkage;
13071300 break;
13081301 case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
1302 case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
13091303 case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
1304 case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
13101305 case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
13111306 case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
13121307 }
13271322 case lltok::kw_default: Res = GlobalValue::DefaultVisibility; break;
13281323 case lltok::kw_hidden: Res = GlobalValue::HiddenVisibility; break;
13291324 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;
13451325 }
13461326 Lex.Lex();
13471327 return false;
29532933 unsigned Linkage;
29542934
29552935 unsigned Visibility;
2956 unsigned DLLStorageClass;
29572936 AttrBuilder RetAttrs;
29582937 CallingConv::ID CC;
29592938 Type *RetType = 0;
29602939 LocTy RetTypeLoc = Lex.getLoc();
29612940 if (ParseOptionalLinkage(Linkage) ||
29622941 ParseOptionalVisibility(Visibility) ||
2963 ParseOptionalDLLStorageClass(DLLStorageClass) ||
29642942 ParseOptionalCallingConv(CC) ||
29652943 ParseOptionalReturnAttrs(RetAttrs) ||
29662944 ParseType(RetType, RetTypeLoc, true /*void allowed*/))
29702948 switch ((GlobalValue::LinkageTypes)Linkage) {
29712949 case GlobalValue::ExternalLinkage:
29722950 break; // always ok.
2951 case GlobalValue::DLLImportLinkage:
29732952 case GlobalValue::ExternalWeakLinkage:
29742953 if (isDefine)
29752954 return Error(LinkageLoc, "invalid linkage for function definition");
29832962 case GlobalValue::LinkOnceODRLinkage:
29842963 case GlobalValue::WeakAnyLinkage:
29852964 case GlobalValue::WeakODRLinkage:
2965 case GlobalValue::DLLExportLinkage:
29862966 if (!isDefine)
29872967 return Error(LinkageLoc, "invalid linkage for function declaration");
29882968 break;
31293109
31303110 Fn->setLinkage((GlobalValue::LinkageTypes)Linkage);
31313111 Fn->setVisibility((GlobalValue::VisibilityTypes)Visibility);
3132 Fn->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
31333112 Fn->setCallingConv(CC);
31343113 Fn->setAttributes(PAL);
31353114 Fn->setUnnamedAddr(UnnamedAddr);
203203 bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
204204 }
205205 bool ParseOptionalVisibility(unsigned &Visibility);
206 bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
207206 bool ParseOptionalCallingConv(CallingConv::ID &CC);
208207 bool ParseOptionalAlignment(unsigned &Alignment);
209208 bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
234233 bool ParseUnnamedGlobal();
235234 bool ParseNamedGlobal();
236235 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
237 bool HasLinkage, unsigned Visibility,
238 unsigned DLLStorageClass);
239 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility,
240 unsigned DLLStorageClass);
236 bool HasLinkage, unsigned Visibility);
237 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
241238 bool ParseStandaloneMetadata();
242239 bool ParseNamedMetadata();
243240 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::ExternalLinkage; // Obsolete DLLImportLinkage
83 case 6: return GlobalValue::ExternalLinkage; // Obsolete DLLExportLinkage
82 case 5: return GlobalValue::DLLImportLinkage;
83 case 6: return GlobalValue::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;
111101 }
112102 }
113103
199189 case bitc::SYNCHSCOPE_SINGLETHREAD: return SingleThread;
200190 default: // Map unknown scopes to cross-thread.
201191 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;
209192 }
210193 }
211194
18131796 }
18141797 // GLOBALVAR: [pointer type, isconst, initid,
18151798 // linkage, alignment, section, visibility, threadlocal,
1816 // unnamed_addr, dllstorageclass]
1799 // unnamed_addr]
18171800 case bitc::MODULE_CODE_GLOBALVAR: {
18181801 if (Record.size() < 6)
18191802 return Error(InvalidRecord);
18591842 NewGV->setVisibility(Visibility);
18601843 NewGV->setUnnamedAddr(UnnamedAddr);
18611844
1862 if (Record.size() > 10)
1863 NewGV->setDLLStorageClass(GetDecodedDLLStorageClass(Record[10]));
1864 else
1865 UpgradeDLLImportExportLinkage(NewGV, Record[3]);
1866
18671845 ValueList.push_back(NewGV);
18681846
18691847 // Remember which value to use for the global initializer.
18721850 break;
18731851 }
18741852 // FUNCTION: [type, callingconv, isproto, linkage, paramattr,
1875 // alignment, section, visibility, gc, unnamed_addr,
1876 // dllstorageclass]
1853 // alignment, section, visibility, gc, unnamed_addr]
18771854 case bitc::MODULE_CODE_FUNCTION: {
18781855 if (Record.size() < 8)
18791856 return Error(InvalidRecord);
19131890 Func->setUnnamedAddr(UnnamedAddr);
19141891 if (Record.size() > 10 && Record[10] != 0)
19151892 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
19221893 ValueList.push_back(Func);
19231894
19241895 // If this is a function with a body, remember the prototype we are
19301901 break;
19311902 }
19321903 // ALIAS: [alias type, aliasee val#, linkage]
1933 // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
1904 // ALIAS: [alias type, aliasee val#, linkage, visibility]
19341905 case bitc::MODULE_CODE_ALIAS: {
19351906 if (Record.size() < 3)
19361907 return Error(InvalidRecord);
19451916 // Old bitcode files didn't have visibility field.
19461917 if (Record.size() > 3)
19471918 NewGA->setVisibility(GetDecodedVisibility(Record[3]));
1948 if (Record.size() > 4)
1949 NewGA->setDLLStorageClass(GetDecodedDLLStorageClass(Record[4]));
1950 else
1951 UpgradeDLLImportExportLinkage(NewGA, Record[2]);
19521919 ValueList.push_back(NewGA);
19531920 AliasInits.push_back(std::make_pair(NewGA, Record[1]));
19541921 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;
483485 case GlobalValue::ExternalWeakLinkage: return 7;
484486 case GlobalValue::CommonLinkage: return 8;
485487 case GlobalValue::PrivateLinkage: return 9;
499501 case GlobalValue::ProtectedVisibility: return 2;
500502 }
501503 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");
511504 }
512505
513506 static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) {
613606
614607 // GLOBALVAR: [type, isconst, initid,
615608 // linkage, alignment, section, visibility, threadlocal,
616 // unnamed_addr, externally_initialized, dllstorageclass]
609 // unnamed_addr, externally_initialized]
617610 Vals.push_back(VE.getTypeID(GV->getType()));
618611 Vals.push_back(GV->isConstant());
619612 Vals.push_back(GV->isDeclaration() ? 0 :
623616 Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
624617 if (GV->isThreadLocal() ||
625618 GV->getVisibility() != GlobalValue::DefaultVisibility ||
626 GV->hasUnnamedAddr() || GV->isExternallyInitialized() ||
627 GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
619 GV->hasUnnamedAddr() || GV->isExternallyInitialized()) {
628620 Vals.push_back(getEncodedVisibility(GV));
629621 Vals.push_back(getEncodedThreadLocalMode(GV));
630622 Vals.push_back(GV->hasUnnamedAddr());
631623 Vals.push_back(GV->isExternallyInitialized());
632 Vals.push_back(getEncodedDLLStorageClass(GV));
633624 } else {
634625 AbbrevToUse = SimpleGVarAbbrev;
635626 }
654645 Vals.push_back(F->hasUnnamedAddr());
655646 Vals.push_back(F->hasPrefixData() ? (VE.getValueID(F->getPrefixData()) + 1)
656647 : 0);
657 Vals.push_back(getEncodedDLLStorageClass(F));
658648
659649 unsigned AbbrevToUse = 0;
660650 Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
669659 Vals.push_back(VE.getValueID(AI->getAliasee()));
670660 Vals.push_back(getEncodedLinkage(AI));
671661 Vals.push_back(getEncodedVisibility(AI));
672 Vals.push_back(getEncodedDLLStorageClass(AI));
673662 unsigned AbbrevToUse = 0;
674663 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
675664 Vals.clear();
256256 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
257257 }
258258 return;
259 case GlobalValue::DLLExportLinkage:
259260 case GlobalValue::AppendingLinkage:
260261 // FIXME: appending linkage variables should go into a section of
261262 // their name or something. For now, just emit them as external.
270271 return;
271272 case GlobalValue::AvailableExternallyLinkage:
272273 llvm_unreachable("Should never emit this");
274 case GlobalValue::DLLImportLinkage:
273275 case GlobalValue::ExternalWeakLinkage:
274276 llvm_unreachable("Don't know how to emit these");
275277 }
12101210 }
12111211
12121212 // If the existing global is strong, never replace it.
1213 if (GVEntry->hasExternalLinkage())
1213 if (GVEntry->hasExternalLinkage() ||
1214 GVEntry->hasDLLImportLinkage() ||
1215 GVEntry->hasDLLExportLinkage())
12141216 continue;
12151217
12161218 // 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;
13691371 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
13701372 case GlobalValue::AvailableExternallyLinkage:
13711373 Out << "available_externally ";
13801382 case GlobalValue::DefaultVisibility: break;
13811383 case GlobalValue::HiddenVisibility: Out << "hidden "; break;
13821384 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;
13921385 }
13931386 }
13941387
14241417
14251418 PrintLinkage(GV->getLinkage(), Out);
14261419 PrintVisibility(GV->getVisibility(), Out);
1427 PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
14281420 PrintThreadLocalModel(GV->getThreadLocalMode(), Out);
14291421
14301422 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
14621454 Out << " = ";
14631455 }
14641456 PrintVisibility(GA->getVisibility(), Out);
1465 PrintDLLStorageClass(GA->getDLLStorageClass(), Out);
14661457
14671458 Out << "alias ";
14681459
15601551
15611552 PrintLinkage(F->getLinkage(), Out);
15621553 PrintVisibility(F->getVisibility(), Out);
1563 PrintDLLStorageClass(F->getDLLStorageClass(), Out);
15641554
15651555 // Print the calling convention.
15661556 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;
11661170 case GlobalValue::ExternalWeakLinkage:
11671171 return LLVMExternalWeakLinkage;
11681172 case GlobalValue::CommonLinkage:
12141218 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
12151219 break;
12161220 case LLVMDLLImportLinkage:
1217 DEBUG(errs()
1218 << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1221 GV->setLinkage(GlobalValue::DLLImportLinkage);
12191222 break;
12201223 case LLVMDLLExportLinkage:
1221 DEBUG(errs()
1222 << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1224 GV->setLinkage(GlobalValue::DLLExportLinkage);
12231225 break;
12241226 case LLVMExternalWeakLinkage:
12251227 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
420420 Assert1(!GV.isDeclaration() ||
421421 GV.isMaterializable() ||
422422 GV.hasExternalLinkage() ||
423 GV.hasDLLImportLinkage() ||
423424 GV.hasExternalWeakLinkage() ||
424425 (isa(GV) &&
425426 (GV.hasLocalLinkage() || GV.hasWeakLinkage())),
426 "Global is external, but doesn't have external or weak linkage!",
427 "Global is external, but doesn't have external or dllimport or weak linkage!",
427428 &GV);
429
430 Assert1(!GV.hasDLLImportLinkage() || GV.isDeclaration(),
431 "Global is marked as dllimport, but not external", &GV);
428432
429433 Assert1(!GV.hasAppendingLinkage() || isa(GV),
430434 "Only global variables can have appending linkage!", &GV);
451455 &GV);
452456 }
453457 } else {
454 Assert1(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),
458 Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
459 GV.hasExternalWeakLinkage(),
455460 "invalid linkage type for global declaration", &GV);
456461 }
457462
495500 }
496501 }
497502 }
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.hasExternalWeakLinkage(),
1080 Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
1081 F.hasExternalWeakLinkage(),
10811082 "invalid linkage type for function declaration", &F);
10821083 } else {
10831084 // Verify that this function (which has a body) is not named "llvm.*". It
11031104 if (F.hasAddressTaken(&U))
11041105 Assert1(0, "Invalid user of intrinsic instruction!", U);
11051106 }
1106
1107 Assert1(!F.hasDLLImportStorageClass() ||
1108 (F.isDeclaration() && F.hasExternalLinkage()) ||
1109 F.hasAvailableExternallyLinkage(),
1110 "Function is marked as dllimport, but not external.", &F);
11111107 }
11121108
11131109 // 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->hasDLLImportStorageClass()) {
546 // If one of GVs is marked as DLLImport, result should be dllimport'ed.
545 if (Src->hasDLLImportLinkage()) {
546 // If one of GVs has DLLImport linkage, 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->hasDLLImportStorageClass()) {
559 } else if (DestIsDeclaration && !Dest->hasDLLImportLinkage()) {
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->hasExternalWeakLinkage()) &&
587 (Src->hasExternalLinkage() || Src->hasExternalWeakLinkage()) &&
586 assert((Dest->hasExternalLinkage() || Dest->hasDLLImportLinkage() ||
587 Dest->hasDLLExportLinkage() || Dest->hasExternalWeakLinkage()) &&
588 (Src->hasExternalLinkage() || Src->hasDLLImportLinkage() ||
589 Src->hasDLLExportLinkage() || Src->hasExternalWeakLinkage()) &&
588590 "Unexpected linkage type!");
589591 return emitError("Linking globals named '" + Src->getName() +
590592 "': symbol multiply defined!");
130130 private:
131131 void printLinkageType(GlobalValue::LinkageTypes LT);
132132 void printVisibilityType(GlobalValue::VisibilityTypes VisTypes);
133 void printDLLStorageClassType(GlobalValue::DLLStorageClassTypes DSCType);
134133 void printThreadLocalMode(GlobalVariable::ThreadLocalMode TLM);
135134 void printCallingConv(CallingConv::ID cc);
136135 void printEscapedString(const std::string& str);
300299 Out << "GlobalValue::AppendingLinkage"; break;
301300 case GlobalValue::ExternalLinkage:
302301 Out << "GlobalValue::ExternalLinkage"; break;
302 case GlobalValue::DLLImportLinkage:
303 Out << "GlobalValue::DLLImportLinkage"; break;
304 case GlobalValue::DLLExportLinkage:
305 Out << "GlobalValue::DLLExportLinkage"; break;
303306 case GlobalValue::ExternalWeakLinkage:
304307 Out << "GlobalValue::ExternalWeakLinkage"; break;
305308 case GlobalValue::CommonLinkage:
317320 break;
318321 case GlobalValue::ProtectedVisibility:
319322 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";
335323 break;
336324 }
337325 }
10391027 Out << ");";
10401028 nl(Out);
10411029 }
1042 if (GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
1043 printCppName(GV);
1044 Out << "->setDLLStorageClass(";
1045 printDLLStorageClassType(GV->getDLLStorageClass());
1046 Out << ");";
1047 nl(Out);
1048 }
10491030 if (GV->isThreadLocal()) {
10501031 printCppName(GV);
10511032 Out << "->setThreadLocalMode(";
17641745 Out << ");";
17651746 nl(Out);
17661747 }
1767 if (F->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
1768 printCppName(F);
1769 Out << "->setDLLStorageClass(";
1770 printDLLStorageClassType(F->getDLLStorageClass());
1771 Out << ");";
1772 nl(Out);
1773 }
17741748 if (F->hasGC()) {
17751749 printCppName(F);
17761750 Out << "->setGC(\"" << F->getGC() << "\");";
648648 // Necessary for dllexport support
649649 std::vector DLLExportedFns, DLLExportedGlobals;
650650
651 const TargetLoweringObjectFileCOFF &TLOFCOFF =
652 static_cast(getObjFileLowering());
653
651654 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
652 if (I->hasDLLExportStorageClass())
655 if (I->hasDLLExportLinkage())
653656 DLLExportedFns.push_back(getSymbol(I));
654657
655658 for (Module::const_global_iterator I = M.global_begin(),
656659 E = M.global_end(); I != E; ++I)
657 if (I->hasDLLExportStorageClass())
660 if (I->hasDLLExportLinkage())
658661 DLLExportedGlobals.push_back(getSymbol(I));
659662
660663 // Output linker support code for dllexported globals on windows.
661664 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->hasDLLImportStorageClass())
699 if (GV->hasDLLImportLinkage())
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->hasDLLImportStorageClass()) {
2798 if (!GV->hasDLLImportLinkage()) {
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->hasDLLImportStorageClass())
57 if (GV->hasDLLImportLinkage())
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!");
137141 default:
138142 llvm_unreachable("Unknown linkage type!");
139143 }
115115 return false;
116116
117117 // Assume that dllexported symbols are referenced elsewhere
118 if (GV.hasDLLExportStorageClass())
118 if (GV.hasDLLExportLinkage())
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 = external dllimport global i32
52 ; CHECK: @dllimport.var = dllimport global i32
5353
5454 define private void @private()
5555 ; CHECK: define private void @private
0 ; 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
-79
test/CodeGen/X86/dllexport-x86_64.ll less more
None ; 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 -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
0 ; RUN: llc < %s | FileCheck %s
1 ; PR2936
22
3 ; CHECK: .text
3 target triple = "i386-pc-mingw32"
44
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 {
5 define dllexport x86_fastcallcc i32 @foo() nounwind {
6 entry:
267 ret i32 0
278 }
289
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
7310 ; CHECK: .section .drectve
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
11 ; CHECK: -export:@foo@0
+0
-48
test/CodeGen/X86/dllimport-x86_64.ll less more
None ; 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
-59
test/CodeGen/X86/dllimport.ll less more
None ; 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 }