compiler: make sure type descriptor initializers go in .rodata
When creating type descriptor variables, the compiler (specifically
Type::make_type_descriptor_var) invokes the immutable_struct() and
immutable_struct_set_init() back end methods, so as to insure that
these items go into the ".rodata" section of the generate object file.
The expression initializers for these variables can contain nested
subexpressions, however, and these subexpressions were not always
being placed into .rodata. This patch changes the backend-gen code for
slice initializers to emit implicit variables into .rodata if those
initializers are part of a type descriptor init.
Change-Id: I2110ccf160ae9469dcad8602f17f0f0c475754f3
Reviewed-on: https://go-review.googlesource.com/132596
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/expressions.cc b/go/expressions.cc
index 143f0a7..efc8eba 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -4453,7 +4453,8 @@
// initialize the value once, so we can use this directly
// rather than copying it. In that case we can't make it
// read-only, because the program is permitted to change it.
- copy_to_heap = context->function() != NULL;
+ copy_to_heap = (context->function() != NULL
+ || context->is_const());
}
std::string asm_name(go_selectively_encode_id(var_name));
Bvariable* implicit =