From e051745c838bf29e564fb2665339f97c8383b9e8 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Tue, 8 Jul 2014 22:34:27 -0700 Subject: Fix --defsym to copy symbol attributes. Alan Modra committed a patch to Gnu ld to fix a problem encountered on PPC where the --defsym option wasn't copying the st_other bits to the newly-defined symbol. https://sourceware.org/ml/binutils/2014-07/msg00094.html Gold has the same problem, and additionally wasn't copying the symbol type. This patch fixes both problems, by copying the symbol type, visibility, and the remaining st_other bits to the new symbol for --defsym=sym1=sym2 assignments. gold/ * expression.cc (struct Expression::Expression_eval_info): Add new fields type_pointer, vis_pointer, and nonvis_pointer. (Expression::eval_maybe_dot): Add type_pointer, vis_pointer, and nonvis_pointer parameters. Adjust all calls. (Symbol_expression::value): Update type, visibility, and nonvis bits in caller. * script.cc (Symbol_assignment::sized_finalize): Update type, visibility, and remaining st_other bits for new symbol. * script.h: (Expression::eval_maybe_dot): Add type_pointer, vis_pointer, and nonvis_pointer parameters. * symtab.h (Symbol::set_type): New method. * testsuite/Makefile.am (defsym_test): New test. * testsuite/Makefile.in: Regenerate. * testsuite/defsym_test.c: New file. * testsuite/defsym_test.sh: New file. --- gold/expression.cc | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'gold/expression.cc') diff --git a/gold/expression.cc b/gold/expression.cc index bdf52fa..61a3eaf 100644 --- a/gold/expression.cc +++ b/gold/expression.cc @@ -68,6 +68,12 @@ struct Expression::Expression_eval_info Output_section** result_section_pointer; // Pointer to where the alignment of the result should be stored. uint64_t* result_alignment_pointer; + // Pointer to where the type of the symbol on the RHS should be stored. + elfcpp::STT* type_pointer; + // Pointer to where the visibility of the symbol on the RHS should be stored. + elfcpp::STV* vis_pointer; + // Pointer to where the rest of the symbol's st_other field should be stored. + unsigned char* nonvis_pointer; }; // Evaluate an expression. @@ -76,8 +82,8 @@ uint64_t Expression::eval(const Symbol_table* symtab, const Layout* layout, bool check_assertions) { - return this->eval_maybe_dot(symtab, layout, check_assertions, - false, 0, NULL, NULL, NULL, false); + return this->eval_maybe_dot(symtab, layout, check_assertions, false, 0, + NULL, NULL, NULL, NULL, NULL, NULL, false); } // Evaluate an expression which may refer to the dot symbol. @@ -92,7 +98,7 @@ Expression::eval_with_dot(const Symbol_table* symtab, const Layout* layout, { return this->eval_maybe_dot(symtab, layout, check_assertions, true, dot_value, dot_section, result_section_pointer, - result_alignment_pointer, + result_alignment_pointer, NULL, NULL, NULL, is_section_dot_assignment); } @@ -105,6 +111,9 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout, uint64_t dot_value, Output_section* dot_section, Output_section** result_section_pointer, uint64_t* result_alignment_pointer, + elfcpp::STT* type_pointer, + elfcpp::STV* vis_pointer, + unsigned char* nonvis_pointer, bool is_section_dot_assignment) { Expression_eval_info eei; @@ -121,6 +130,12 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout, *result_section_pointer = NULL; eei.result_section_pointer = result_section_pointer; + // For symbol=symbol assignments, we need to track the type, visibility, + // and remaining st_other bits. + eei.type_pointer = type_pointer; + eei.vis_pointer = vis_pointer; + eei.nonvis_pointer = nonvis_pointer; + eei.result_alignment_pointer = result_alignment_pointer; uint64_t val = this->value(&eei); @@ -196,6 +211,12 @@ Symbol_expression::value(const Expression_eval_info* eei) if (eei->result_section_pointer != NULL) *eei->result_section_pointer = sym->output_section(); + if (eei->type_pointer != NULL) + *eei->type_pointer = sym->type(); + if (eei->vis_pointer != NULL) + *eei->vis_pointer = sym->visibility(); + if (eei->nonvis_pointer != NULL) + *eei->nonvis_pointer = sym->nonvis(); if (parameters->target().get_size() == 32) return eei->symtab->get_sized_symbol<32>(sym)->value(); @@ -271,6 +292,9 @@ class Unary_expression : public Expression eei->dot_section, arg_section_pointer, eei->result_alignment_pointer, + NULL, + NULL, + NULL, false); } @@ -351,6 +375,9 @@ class Binary_expression : public Expression eei->dot_section, section_pointer, alignment_pointer, + NULL, + NULL, + NULL, false); } @@ -366,6 +393,9 @@ class Binary_expression : public Expression eei->dot_section, section_pointer, alignment_pointer, + NULL, + NULL, + NULL, false); } @@ -517,6 +547,9 @@ class Trinary_expression : public Expression eei->dot_section, section_pointer, NULL, + NULL, + NULL, + NULL, false); } @@ -532,6 +565,9 @@ class Trinary_expression : public Expression eei->dot_section, section_pointer, alignment_pointer, + NULL, + NULL, + NULL, false); } @@ -547,6 +583,9 @@ class Trinary_expression : public Expression eei->dot_section, section_pointer, alignment_pointer, + NULL, + NULL, + NULL, false); } -- cgit v1.1