Skip to content

Commit b483d0e

Browse files
compiler, libgo: change mangling scheme
Overhaul the mangling scheme to avoid ambiguities if the package path contains a dot. Instead of using dot both to separate components and to mangle characters, use dot only to separate components and use underscore to mangle characters. For golang/go#41862 Change-Id: Iddc04422673a4cdc6773d24d3d75fc8945266773 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/271726 Trust: Ian Lance Taylor <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent c948c2d commit b483d0e

56 files changed

Lines changed: 1326 additions & 943 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go/ast-dump.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ Ast_dump_context::dump_type(const Type* t)
226226
// FIXME: write a type pretty printer instead of
227227
// using mangled names.
228228
if (this->gogo_ != NULL)
229-
this->ostream() << "(" << t->mangled_name(this->gogo_) << ")";
229+
{
230+
Backend_name bname;
231+
t->backend_name(this->gogo_, &bname);
232+
this->ostream() << "(" << bname.name() << ")";
233+
}
230234
}
231235

232236
// Dump a textual representation of a block to the

go/export.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ should_export(Named_object* no)
461461
return false;
462462

463463
// We don't export various special functions.
464-
if (Gogo::is_special_name(no->name()))
464+
if (Gogo::special_name_pos(no->name()) != std::string::npos)
465465
return false;
466466

467467
// Methods are exported with the type, not here.
@@ -524,7 +524,11 @@ struct Sort_types
524524
if (t1->classification() != t2->classification())
525525
return t1->classification() < t2->classification();
526526
Gogo* gogo = go_get_gogo();
527-
return gogo->type_descriptor_name(t1, NULL).compare(gogo->type_descriptor_name(t2, NULL)) < 0;
527+
Backend_name b1;
528+
gogo->type_descriptor_backend_name(t1, NULL, &b1);
529+
Backend_name b2;
530+
gogo->type_descriptor_backend_name(t2, NULL, &b2);
531+
return b1.name() < b2.name();
528532
}
529533
};
530534

go/expressions.cc

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,8 @@ Func_descriptor_expression::do_get_backend(Translate_context* context)
15961596
return context->backend()->var_expression(this->dvar_, loc);
15971597

15981598
Gogo* gogo = context->gogo();
1599-
std::string var_name(gogo->function_descriptor_name(no));
1599+
Backend_name bname;
1600+
gogo->function_descriptor_backend_name(no, &bname);
16001601
bool is_descriptor = false;
16011602
if (no->is_function_declaration()
16021603
&& !no->func_declaration_value()->asm_name().empty()
@@ -1616,10 +1617,11 @@ Func_descriptor_expression::do_get_backend(Translate_context* context)
16161617
Btype* btype = this->type()->get_backend(gogo);
16171618

16181619
Bvariable* bvar;
1619-
std::string asm_name(go_selectively_encode_id(var_name));
16201620
if (no->package() != NULL || is_descriptor)
1621-
bvar = context->backend()->immutable_struct_reference(var_name, asm_name,
1622-
btype, loc);
1621+
bvar =
1622+
context->backend()->immutable_struct_reference(bname.name(),
1623+
bname.optional_asm_name(),
1624+
btype, loc);
16231625
else
16241626
{
16251627
Location bloc = Linemap::predeclared_location();
@@ -1644,7 +1646,8 @@ Func_descriptor_expression::do_get_backend(Translate_context* context)
16441646
if (no->is_function() && no->func_value()->is_referenced_by_inline())
16451647
is_hidden = false;
16461648

1647-
bvar = context->backend()->immutable_struct(var_name, asm_name,
1649+
bvar = context->backend()->immutable_struct(bname.name(),
1650+
bname.optional_asm_name(),
16481651
is_hidden, false,
16491652
btype, bloc);
16501653
Expression_list* vals = new Expression_list();
@@ -1654,8 +1657,9 @@ Func_descriptor_expression::do_get_backend(Translate_context* context)
16541657
Translate_context bcontext(gogo, NULL, NULL, NULL);
16551658
bcontext.set_is_const();
16561659
Bexpression* binit = init->get_backend(&bcontext);
1657-
context->backend()->immutable_struct_set_init(bvar, var_name, is_hidden,
1658-
false, btype, bloc, binit);
1660+
context->backend()->immutable_struct_set_init(bvar, bname.name(),
1661+
is_hidden, false, btype,
1662+
bloc, binit);
16591663
}
16601664

16611665
this->dvar_ = bvar;
@@ -5190,11 +5194,9 @@ Unary_expression::do_get_backend(Translate_context* context)
51905194
copy_to_heap = (context->function() != NULL
51915195
|| context->is_const());
51925196
}
5193-
std::string asm_name(go_selectively_encode_id(var_name));
51945197
Bvariable* implicit =
5195-
gogo->backend()->implicit_variable(var_name, asm_name,
5196-
btype, true, copy_to_heap,
5197-
false, 0);
5198+
gogo->backend()->implicit_variable(var_name, "", btype, true,
5199+
copy_to_heap, false, 0);
51985200
gogo->backend()->implicit_variable_set_init(implicit, var_name, btype,
51995201
true, copy_to_heap, false,
52005202
bexpr);
@@ -5219,20 +5221,18 @@ Unary_expression::do_get_backend(Translate_context* context)
52195221
&& this->expr_->is_static_initializer())
52205222
{
52215223
std::string var_name(gogo->initializer_name());
5222-
std::string asm_name(go_selectively_encode_id(var_name));
52235224
Bvariable* decl =
5224-
gogo->backend()->immutable_struct(var_name, asm_name,
5225-
true, false, btype, loc);
5225+
gogo->backend()->immutable_struct(var_name, "", true, false,
5226+
btype, loc);
52265227
gogo->backend()->immutable_struct_set_init(decl, var_name, true,
52275228
false, btype, loc, bexpr);
52285229
bexpr = gogo->backend()->var_expression(decl, loc);
52295230
}
52305231
else if (this->expr_->is_constant())
52315232
{
52325233
std::string var_name(gogo->initializer_name());
5233-
std::string asm_name(go_selectively_encode_id(var_name));
52345234
Bvariable* decl =
5235-
gogo->backend()->implicit_variable(var_name, asm_name, btype,
5235+
gogo->backend()->implicit_variable(var_name, "", btype,
52365236
true, true, false, 0);
52375237
gogo->backend()->implicit_variable_set_init(decl, var_name, btype,
52385238
true, true, false,
@@ -18251,9 +18251,8 @@ Interface_mtable_expression::do_get_backend(Translate_context* context)
1825118251
{
1825218252
// The interface conversion table is defined elsewhere.
1825318253
Btype* btype = this->type()->get_backend(gogo);
18254-
std::string asm_name(go_selectively_encode_id(mangled_name));
1825518254
this->bvar_ =
18256-
gogo->backend()->immutable_struct_reference(mangled_name, asm_name,
18255+
gogo->backend()->immutable_struct_reference(mangled_name, "",
1825718256
btype, loc);
1825818257
return gogo->backend()->var_expression(this->bvar_, this->location());
1825918258
}
@@ -18323,8 +18322,7 @@ Interface_mtable_expression::do_get_backend(Translate_context* context)
1832318322
Bexpression* ctor =
1832418323
gogo->backend()->constructor_expression(btype, ctor_bexprs, loc);
1832518324

18326-
std::string asm_name(go_selectively_encode_id(mangled_name));
18327-
this->bvar_ = gogo->backend()->immutable_struct(mangled_name, asm_name, false,
18325+
this->bvar_ = gogo->backend()->immutable_struct(mangled_name, "", false,
1832818326
!is_public, btype, loc);
1832918327
gogo->backend()->immutable_struct_set_init(this->bvar_, mangled_name, false,
1833018328
!is_public, btype, loc, ctor);

0 commit comments

Comments
 (0)