compiler: drop special handling of unexported func/var assembler names

For example, for the package math/big, we used to generate unexported
names as `big.trim` and exported names as `math_big.NewInt`.  After
this change we will use `math_big` consistently.

Change-Id: Ie7cf87f1bebfe4e90ad58d328521d7910e156d28
Reviewed-on: https://go-review.googlesource.com/68651
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/go/gogo.cc b/go/gogo.cc
index da8f3c5..c986963 100644
--- a/go/gogo.cc
+++ b/go/gogo.cc
@@ -5343,8 +5343,9 @@
 {
   if (this->fndecl_ == NULL)
     {
-      std::string asm_name;
       bool is_visible = false;
+      bool is_init_fn = false;
+      Type* rtype = NULL;
       if (no->package() != NULL)
         ;
       else if (this->enclosing_ != NULL || Gogo::is_thunk(no))
@@ -5355,7 +5356,7 @@
       else if (no->name() == gogo->get_init_fn_name())
 	{
 	  is_visible = true;
-	  asm_name = no->name();
+	  is_init_fn = true;
 	}
       else if (Gogo::unpack_hidden_name(no->name()) == "main"
                && gogo->is_main_package())
@@ -5368,17 +5369,29 @@
         {
 	  if (!this->is_unnamed_type_stub_method_)
 	    is_visible = true;
-	  Type* rtype = NULL;
 	  if (this->type_->is_method())
 	    rtype = this->type_->receiver()->type();
-	  asm_name = gogo->function_asm_name(no->name(), NULL, rtype);
         }
 
+      std::string asm_name;
       if (!this->asm_name_.empty())
 	{
 	  asm_name = this->asm_name_;
+
+	  // If an assembler name is explicitly specified, there must
+	  // be some reason to refer to the symbol from a different
+	  // object file.
 	  is_visible = true;
 	}
+      else if (is_init_fn)
+	{
+	  // These names appear in the export data and are used
+	  // directly in the assembler code.  If we change this here
+	  // we need to change Gogo::init_imports.
+	  asm_name = no->name();
+	}
+      else
+	asm_name = gogo->function_asm_name(no->name(), NULL, rtype);
 
       // If a function calls the predeclared recover function, we
       // can't inline it, because recover behaves differently in a
@@ -5409,10 +5422,6 @@
       if ((this->pragmas_ & GOPRAGMA_NOSPLIT) != 0)
 	disable_split_stack = true;
 
-      // Encode name if asm_name not already set at this point
-      if (asm_name.empty())
-	asm_name = gogo->unexported_function_asm_name(no->name());
-
       // This should go into a unique section if that has been
       // requested elsewhere, or if this is a nointerface function.
       // We want to put a nointerface function into a unique section
diff --git a/go/gogo.h b/go/gogo.h
index 018aca5..345a15d 100644
--- a/go/gogo.h
+++ b/go/gogo.h
@@ -767,10 +767,6 @@
   function_asm_name(const std::string& go_name, const Package*,
 		    const Type* receiver);
 
-  // Return the assembler name to use for an unexported function.
-  std::string
-  unexported_function_asm_name(const std::string& go_name);
-
   // Return the name to use for a function descriptor.
   std::string
   function_descriptor_name(Named_object*);
diff --git a/go/names.cc b/go/names.cc
index 48ffec0..20f7c57 100644
--- a/go/names.cc
+++ b/go/names.cc
@@ -54,19 +54,6 @@
   return go_encode_id(ret);
 }
 
-// Return the assembler name to use for an unexported function.
-// FIXME: This should probably be removed and the callers changed to
-// simply call function_name.
-
-std::string
-Gogo::unexported_function_asm_name(const std::string& go_name)
-{
-  std::string ret = this->package_name();
-  ret.append(1, '.');
-  ret.append(Gogo::unpack_hidden_name(go_name));
-  return go_encode_id(ret);
-}
-
 // Return the name to use for a function descriptor.  These symbols
 // are globally visible.
 
@@ -171,18 +158,9 @@
 std::string
 Gogo::global_var_asm_name(const std::string& go_name, const Package* package)
 {
-  // FIXME: Using package_name for hidden names and pkgpath_symbol for
-  // non-hidden names doesn't make sense, but it dates back to the
-  // first public commit of the gofrontend repo.
-  std::string ret;
-  if (Gogo::is_hidden_name(go_name))
-    ret = (package != NULL
-	   ? package->package_name()
-	   : this->package_name());
-  else
-    ret = (package != NULL
-	   ? package->pkgpath_symbol()
-	   : this->pkgpath_symbol());
+  std::string ret = (package != NULL
+		     ? package->pkgpath_symbol()
+		     : this->pkgpath_symbol());
   ret.push_back('.');
   ret.append(Gogo::unpack_hidden_name(go_name));
   return go_encode_id(ret);