View | Details | Raw Unified | Return to bug 19823
Collapse All | Expand All

(-)a/gold/copy-relocs.cc (-2 / +14 lines)
Lines 48-54 Copy_relocs<sh_type, size, big_endian>::copy_reloc( Link Here
48
    Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
48
    Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
49
{
49
{
50
  if (this->need_copy_reloc(sym, object, shndx))
50
  if (this->need_copy_reloc(sym, object, shndx))
51
    this->make_copy_reloc(symtab, layout, sym, reloc_section);
51
    this->make_copy_reloc(symtab, layout, sym, object, reloc_section);
52
  else
52
  else
53
    {
53
    {
54
      // We may not need a COPY relocation.  Save this relocation to
54
      // We may not need a COPY relocation.  Save this relocation to
Lines 111-121 Copy_relocs<sh_type, size, big_endian>::make_copy_reloc( Link Here
111
    Symbol_table* symtab,
111
    Symbol_table* symtab,
112
    Layout* layout,
112
    Layout* layout,
113
    Sized_symbol<size>* sym,
113
    Sized_symbol<size>* sym,
114
    Sized_relobj_file<size, big_endian>* object,
114
    Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
115
    Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
115
{
116
{
116
  // We should not be here if -z nocopyreloc is given.
117
  // We should not be here if -z nocopyreloc is given.
117
  gold_assert(parameters->options().copyreloc());
118
  gold_assert(parameters->options().copyreloc());
118
119
120
  gold_assert(sym->is_from_dynobj());
121
122
  // The symbol must not have protected visibility.
123
  if (sym->is_protected())
124
    {
125
      gold_error(_("%s: cannot make copy relocation for "
126
		   "protected symbol '%s', defined in %s"),
127
		 object->name().c_str(),
128
		 sym->name(),
129
		 sym->object()->name().c_str());
130
    }
131
119
  typename elfcpp::Elf_types<size>::Elf_WXword symsize = sym->symsize();
132
  typename elfcpp::Elf_types<size>::Elf_WXword symsize = sym->symsize();
120
133
121
  // There is no defined way to determine the required alignment of
134
  // There is no defined way to determine the required alignment of
Lines 124-130 Copy_relocs<sh_type, size, big_endian>::make_copy_reloc( Link Here
124
  // is defined; presumably we do not require an alignment larger than
137
  // is defined; presumably we do not require an alignment larger than
125
  // that.  Then we reduce that alignment if the symbol is not aligned
138
  // that.  Then we reduce that alignment if the symbol is not aligned
126
  // within the section.
139
  // within the section.
127
  gold_assert(sym->is_from_dynobj());
128
  bool is_ordinary;
140
  bool is_ordinary;
129
  unsigned int shndx = sym->shndx(&is_ordinary);
141
  unsigned int shndx = sym->shndx(&is_ordinary);
130
  gold_assert(is_ordinary);
142
  gold_assert(is_ordinary);
(-)a/gold/copy-relocs.h (+1 lines)
Lines 123-128 class Copy_relocs Link Here
123
  // Make a new COPY reloc and emit it.
123
  // Make a new COPY reloc and emit it.
124
  void
124
  void
125
  make_copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>*,
125
  make_copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>*,
126
		  Sized_relobj_file<size, big_endian>* object,
126
		  Output_data_reloc<sh_type, true, size, big_endian>*);
127
		  Output_data_reloc<sh_type, true, size, big_endian>*);
127
128
128
  // A list of relocs to be saved.
129
  // A list of relocs to be saved.
(-)a/gold/mips.cc (+1 lines)
Lines 7750-7755 Mips_copy_relocs<sh_type, size, big_endian>::emit_entry( Link Here
7750
  else
7750
  else
7751
    this->make_copy_reloc(symtab, layout,
7751
    this->make_copy_reloc(symtab, layout,
7752
                          static_cast<Sized_symbol<size>*>(entry.sym_),
7752
                          static_cast<Sized_symbol<size>*>(entry.sym_),
7753
                          entry.relobj_,
7753
                          reloc_section);
7754
                          reloc_section);
7754
}
7755
}
7755
7756
(-)a/gold/symtab.cc (+8 lines)
Lines 80-85 Symbol::init_fields(const char* name, const char* version, Link Here
80
  this->undef_binding_set_ = false;
80
  this->undef_binding_set_ = false;
81
  this->undef_binding_weak_ = false;
81
  this->undef_binding_weak_ = false;
82
  this->is_predefined_ = false;
82
  this->is_predefined_ = false;
83
  this->is_protected_ = false;
83
}
84
}
84
85
85
// Return the demangled version of the symbol's name, but only
86
// Return the demangled version of the symbol's name, but only
Lines 1610-1615 Symbol_table::add_from_dynobj( Link Here
1610
	  && res->object() == dynobj)
1611
	  && res->object() == dynobj)
1611
	object_symbols.push_back(res);
1612
	object_symbols.push_back(res);
1612
1613
1614
      // If the symbol has protected visibility in the dynobj,
1615
      // mark it as such if it was not overridden.
1616
      if (res->source() == Symbol::FROM_OBJECT
1617
          && res->object() == dynobj
1618
          && sym.get_st_visibility() == elfcpp::STV_PROTECTED)
1619
        res->set_is_protected();
1620
1613
      if (sympointers != NULL)
1621
      if (sympointers != NULL)
1614
	(*sympointers)[i] = res;
1622
	(*sympointers)[i] = res;
1615
    }
1623
    }
(-)a/gold/symtab.h (+17 lines)
Lines 870-875 class Symbol Link Here
870
  is_cxx_vtable() const
870
  is_cxx_vtable() const
871
  { return is_prefix_of("_ZTV", this->name_); }
871
  { return is_prefix_of("_ZTV", this->name_); }
872
872
873
  // Return true if this symbol is protected in a shared object.
874
  // This is not the same as checking if visibility() == elfcpp::STV_PROTECTED,
875
  // because the visibility_ field reflects the symbol's visibility from
876
  // outside the shared object.
877
  bool
878
  is_protected() const
879
  { return this->is_protected_; }
880
881
  // Mark this symbol as protected in a shared object.
882
  void
883
  set_is_protected()
884
  { this->is_protected_ = true; }
885
873
 protected:
886
 protected:
874
  // Instances of this class should always be created at a specific
887
  // Instances of this class should always be created at a specific
875
  // size.
888
  // size.
Lines 1067-1072 class Symbol Link Here
1067
  bool undef_binding_weak_ : 1;
1080
  bool undef_binding_weak_ : 1;
1068
  // True if this symbol is a predefined linker symbol (bit 34).
1081
  // True if this symbol is a predefined linker symbol (bit 34).
1069
  bool is_predefined_ : 1;
1082
  bool is_predefined_ : 1;
1083
  // True if this symbol has protected visibility in a shared object (bit 35).
1084
  // The visibility_ field will be STV_DEFAULT in this case because we
1085
  // must treat it as such from outside the shared object.
1086
  bool is_protected_  : 1;
1070
};
1087
};
1071
1088
1072
// The parts of a symbol which are size specific.  Using a template
1089
// The parts of a symbol which are size specific.  Using a template
(-)a/gold/testsuite/Makefile.am (+12 lines)
Lines 848-853 copy_test_2_pic.o: copy_test_2.cc Link Here
848
copy_test_2.so: gcctestdir/ld copy_test_2_pic.o
848
copy_test_2.so: gcctestdir/ld copy_test_2_pic.o
849
	$(CXXLINK) -Bgcctestdir/ -shared copy_test_2_pic.o
849
	$(CXXLINK) -Bgcctestdir/ -shared copy_test_2_pic.o
850
850
851
check_SCRIPTS += copy_test_protected.sh
852
check_DATA += copy_test_protected.err
853
MOSTLYCLEANFILES += copy_test_protected.err
854
copy_test_protected.err: copy_test_protected.o copy_test_2.so gcctestdir/ld
855
	@echo $(CXXLINK) -Bgcctestdir/ -o copy_test_protected copy_test_protected.o copy_test_2.so -Wl,-R,. "2>$@"
856
	@if $(CXXLINK) -Bgcctestdir/ -o copy_test_protected copy_test_protected.o copy_test_2.so -Wl,-R,. 2>$@; \
857
	then \
858
	  echo 1>&2 "Link of copy_test_protected should have failed"; \
859
	  rm -f $@; \
860
	  exit 1; \
861
	fi
862
851
if TLS
863
if TLS
852
864
853
check_PROGRAMS += tls_test
865
check_PROGRAMS += tls_test
(-)a/gold/testsuite/copy_test.cc (+4 lines)
Lines 31-36 extern char b; Link Here
31
31
32
// From copy_test_2.cc.
32
// From copy_test_2.cc.
33
extern long long l;
33
extern long long l;
34
extern int ip; // protected visibility; may not be copied
35
36
int* ipp = &ip;
34
37
35
int
38
int
36
main()
39
main()
Lines 39-43 main() Link Here
39
  assert(b == 1);
42
  assert(b == 1);
40
  assert(l == 2);
43
  assert(l == 2);
41
  assert((reinterpret_cast<uintptr_t>(&l) & 0x7) == 0);
44
  assert((reinterpret_cast<uintptr_t>(&l) & 0x7) == 0);
45
  assert(*ipp == 3);
42
  return 0;
46
  return 0;
43
}
47
}
(-)a/gold/testsuite/copy_test_2.cc (+2 lines)
Lines 21-23 Link Here
21
// MA 02110-1301, USA.
21
// MA 02110-1301, USA.
22
22
23
long long l = 2;
23
long long l = 2;
24
25
int ip __attribute__((visibility("protected"))) = 3;
(-)a/gold/testsuite/copy_test_protected.cc (+36 lines)
Line 0 Link Here
1
// copy_test_protected.cc -- test copy relocs for gold
2
3
// Copyright (C) 2016 Free Software Foundation, Inc.
4
// Written by Cary Coutant <ccoutant@gmail.com>.
5
6
// This file is part of gold.
7
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 3 of the License, or
11
// (at your option) any later version.
12
13
// This program is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
// GNU General Public License for more details.
17
18
// You should have received a copy of the GNU General Public License
19
// along with this program; if not, write to the Free Software
20
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
// MA 02110-1301, USA.
22
23
#include <cassert>
24
#include <stdint.h>
25
26
// From copy_test_2.cc.
27
extern int ip; // protected visibility; may not be copied
28
29
int
30
main()
31
{
32
  // This should produce a link-time error because we cannot
33
  // create a copy relocation to a protected symbol.
34
  assert(ip == 3);
35
  return 0;
36
}
(-)a/gold/testsuite/copy_test_protected.sh (+40 lines)
Line 0 Link Here
1
#!/bin/sh
2
3
# copy_test_protected.sh -- a test case for copy relocations.
4
5
# Copyright (C) 2016 Free Software Foundation, Inc.
6
# Written by Cary Coutant <ccoutant@gmail.com>.
7
8
# This file is part of gold.
9
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 3 of the License, or
13
# (at your option) any later version.
14
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23
# MA 02110-1301, USA.
24
25
check()
26
{
27
    if ! grep -q "$2" "$1"
28
    then
29
	echo "Did not find expected error in $1:"
30
	echo "   $2"
31
	echo ""
32
	echo "Actual error output below:"
33
	cat "$1"
34
	exit 1
35
    fi
36
}
37
38
check copy_test_protected.err "protected symbol .ip."
39
40
exit 0
(-)a/gold/testsuite/copy_test_v1.cc (+4 lines)
Lines 35-40 extern char b; Link Here
35
35
36
// From copy_test_2.cc.
36
// From copy_test_2.cc.
37
extern long long l;
37
extern long long l;
38
extern int ip; // protected visibility; may not be copied
39
40
int* ipp = &ip;
38
41
39
int
42
int
40
main()
43
main()
Lines 43-47 main() Link Here
43
  assert(b == 1);
46
  assert(b == 1);
44
  assert(l == 3);	// Deliberately incorrect.
47
  assert(l == 3);	// Deliberately incorrect.
45
  assert((reinterpret_cast<uintptr_t>(&l) & 0x7) == 0);
48
  assert((reinterpret_cast<uintptr_t>(&l) & 0x7) == 0);
49
  assert(*ipp == 3);
46
  return 0;
50
  return 0;
47
}
51
}

Return to bug 19823