[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-bugs
Subject:    [LLVMbugs] [PATCH] Returning InternalLinkage types from
From:       Evan Jones <ejones () uwaterloo ! ca>
Date:       2005-11-22 20:45:58
Message-ID: 894c4c89165a6d3ad73236ce6541f504 () uwaterloo ! ca
[Download RAW message or body]

On Nov 2, 2005, at 17:10, Chris Lattner wrote:
> On Wed, 2 Nov 2005, Evan Jones wrote:
>> In a vaguely related node, why does Module::getGlobalVariable *not* 
>> return types with internal linkage? There must be some logic behind 
>> that choice that I can't figure out. It is easy to copy the code out 
>> of Module.cpp if you need to find variables with internal linkage, 
>> but it seems unnecessary to me.
> Good question.  I think that this method was pulled out of the linker 
> originally, which didn't want to link against internal symbols.  Other 
> clients (such as the lowergc pass) want to get the variable and the 
> var must be an external symbol.

> If you want to add a 'bool AllowInternal' option to the method, and 
> default it to false, go for it.  Please submit the patch to the 
> llvmbugs list if you choose to do so.

The attached patch is the followup from this discussion on llvmdev. It 
does not change the test suite results on my Linux system.

Evan Jones

["getglobal.patch" (getglobal.patch)]

Index: include/llvm/Module.h
===================================================================
RCS file: /var/cvs/llvm/llvm/include/llvm/Module.h,v
retrieving revision 1.64
diff -u -r1.64 Module.h
--- include/llvm/Module.h	25 Oct 2005 17:58:00 -0000	1.64
+++ include/llvm/Module.h	22 Nov 2005 20:43:21 -0000
@@ -137,13 +137,13 @@
   //
 
   /// getGlobalVariable - Look up the specified global variable in the module
-  /// symbol table.  If it does not exist, return null.  Note that this only
-  /// returns a global variable if it does not have internal linkage.  The type
-  /// argument should be the underlying type of the global, i.e., it should not
-  /// have the top-level PointerType, which represents the address of the
-  /// global.
+  /// symbol table.  If it does not exist, return null.  The type argument
+  /// should be the underlying type of the global, i.e., it should not have
+  /// the top-level PointerType, which represents the address of the global.
+  /// If AllowInternal is set to true, this function will return types that
+  /// have InternalLinkage. By default, these types are not returned.
   ///
-  GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty);
+  GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty, bool AllowInternal=false);
 
 
   //===--------------------------------------------------------------------===//
Index: lib/VMCore/Module.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/VMCore/Module.cpp,v
retrieving revision 1.61
diff -u -r1.61 Module.cpp
--- lib/VMCore/Module.cpp	21 Apr 2005 23:46:51 -0000	1.61
+++ lib/VMCore/Module.cpp	22 Nov 2005 20:43:22 -0000
@@ -206,17 +206,17 @@
 //
 
 /// getGlobalVariable - Look up the specified global variable in the module
-/// symbol table.  If it does not exist, return null.  Note that this only
-/// returns a global variable if it does not have internal linkage.  The type
-/// argument should be the underlying type of the global, ie, it should not
-/// have the top-level PointerType, which represents the address of the
-/// global.
+/// symbol table.  If it does not exist, return null.  The type argument
+/// should be the underlying type of the global, i.e., it should not have
+/// the top-level PointerType, which represents the address of the global.
+/// If AllowInternal is set to true, this function will return types that
+/// have InternalLinkage. By default, these types are not returned.
 ///
 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
-                                          const Type *Ty) {
+                                          const Type *Ty, bool AllowInternal) {
   if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) {
     GlobalVariable *Result = cast<GlobalVariable>(V);
-    if (!Result->hasInternalLinkage())
+    if (AllowInternal || !Result->hasInternalLinkage())
       return Result;
   }
   return 0;


--
Evan Jones
http://evanjones.ca/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic