* i386.cc (Target_i386::got_section): If -z now, make .got.plt a

relro section.
	* x86_64.cc (Target_x86_64::got_section): Likewise.
	* testsuite/Makefile.am (check_PROGRAMS): Add relro_now_test.
	(relro_now_test_SOURCES): New variable.
	(relro_now_test_DEPENDENCIES): New variable.
	(relro_now_test_LDFLAGS): New variable.
	(relro_now_test_LDADD): New variable.
	(relro_now_test.so): New target.
	* testsuite/Makefile.in: Rebuild.
This commit is contained in:
Ian Lance Taylor 2011-07-13 22:47:08 +00:00
parent 67f41397ce
commit 9446efde0a
5 changed files with 86 additions and 20 deletions

View File

@ -1,3 +1,16 @@
2011-07-13 Ian Lance Taylor <iant@google.com>
* i386.cc (Target_i386::got_section): If -z now, make .got.plt a
relro section.
* x86_64.cc (Target_x86_64::got_section): Likewise.
* testsuite/Makefile.am (check_PROGRAMS): Add relro_now_test.
(relro_now_test_SOURCES): New variable.
(relro_now_test_DEPENDENCIES): New variable.
(relro_now_test_LDFLAGS): New variable.
(relro_now_test_LDADD): New variable.
(relro_now_test.so): New target.
* testsuite/Makefile.in: Rebuild.
2011-07-12 Ian Lance Taylor <iant@google.com>
PR gold/12980

View File

@ -712,23 +712,37 @@ Target_i386::got_section(Symbol_table* symtab, Layout* layout)
this->got_ = new Output_data_got<32, false>();
// When using -z now, we can treat .got.plt as a relro section.
// Without -z now, it is modified after program startup by lazy
// PLT relocations.
bool is_got_plt_relro = parameters->options().now();
Output_section_order got_order = (is_got_plt_relro
? ORDER_RELRO
: ORDER_RELRO_LAST);
Output_section_order got_plt_order = (is_got_plt_relro
? ORDER_RELRO
: ORDER_NON_RELRO_FIRST);
layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_, ORDER_RELRO_LAST, true);
this->got_, got_order, true);
this->got_plt_ = new Output_data_space(4, "** GOT PLT");
layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_plt_, ORDER_NON_RELRO_FIRST,
false);
this->got_plt_, got_plt_order,
is_got_plt_relro);
// The first three entries are reserved.
this->got_plt_->set_current_data_size(3 * 4);
// Those bytes can go into the relro segment.
layout->increase_relro(3 * 4);
if (!is_got_plt_relro)
{
// Those bytes can go into the relro segment.
layout->increase_relro(3 * 4);
}
// Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
this->global_offset_table_ =
@ -747,7 +761,7 @@ Target_i386::got_section(Symbol_table* symtab, Layout* layout)
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_irelative_,
ORDER_NON_RELRO_FIRST, false);
got_plt_order, is_got_plt_relro);
// If there are any TLSDESC relocations, they get GOT entries in
// .got.plt after the jump slot entries.
@ -756,7 +770,7 @@ Target_i386::got_section(Symbol_table* symtab, Layout* layout)
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_tlsdesc_,
ORDER_NON_RELRO_FIRST, false);
got_plt_order, is_got_plt_relro);
}
return this->got_;

View File

@ -1163,6 +1163,14 @@ relro_test_pic.o: relro_test.cc
relro_test.stdout: relro_test.so
$(TEST_READELF) -SlW relro_test.so > relro_test.stdout
check_PROGRAMS += relro_now_test
relro_now_test_SOURCES = relro_test_main.cc
relro_now_test_DEPENDENCIES = gcctestdir/ld relro_now_test.so
relro_now_test_LDFLAGS = -Bgcctestdir -Wl,-R,. -Wl,-z,relro -Wl,-z,now
relro_now_test_LDADD = relro_now_test.so
relro_now_test.so: gcctestdir/ld relro_test_pic.o
$(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro -Wl,-z,now relro_test_pic.o
check_PROGRAMS += relro_strip_test
relro_strip_test_SOURCES = relro_test_main.cc
relro_strip_test_DEPENDENCIES = gcctestdir/ld relro_strip_test.so

View File

@ -258,7 +258,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_6 ver_test_8 ver_test_9 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11 ver_test_12 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1 protected_2 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test relro_strip_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test relro_now_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_strip_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_script_test script_test_1 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test script_test_3 \
@ -662,6 +663,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_now_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_strip_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_script_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1$(EXEEXT) \
@ -1223,6 +1225,11 @@ protected_1_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
protected_2_OBJECTS = $(am_protected_2_OBJECTS)
protected_2_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(protected_2_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_now_test_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT)
relro_now_test_OBJECTS = $(am_relro_now_test_OBJECTS)
relro_now_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(relro_now_test_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_script_test_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT)
relro_script_test_OBJECTS = $(am_relro_script_test_OBJECTS)
@ -1612,10 +1619,10 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
plugin_test_2.c plugin_test_3.c plugin_test_4.c \
plugin_test_5.c plugin_test_6.c plugin_test_7.c \
plugin_test_8.c $(protected_1_SOURCES) $(protected_2_SOURCES) \
$(relro_script_test_SOURCES) $(relro_strip_test_SOURCES) \
$(relro_test_SOURCES) $(script_test_1_SOURCES) \
$(script_test_2_SOURCES) script_test_3.c \
$(searched_file_test_SOURCES) start_lib_test.c \
$(relro_now_test_SOURCES) $(relro_script_test_SOURCES) \
$(relro_strip_test_SOURCES) $(relro_test_SOURCES) \
$(script_test_1_SOURCES) $(script_test_2_SOURCES) \
script_test_3.c $(searched_file_test_SOURCES) start_lib_test.c \
$(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \
$(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \
tls_pie_pic_test.c tls_pie_test.c $(tls_script_test_SOURCES) \
@ -2231,6 +2238,10 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_DEPENDENCIES = gcctestdir/ld relro_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_LDADD = relro_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_now_test_SOURCES = relro_test_main.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_now_test_DEPENDENCIES = gcctestdir/ld relro_now_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_now_test_LDFLAGS = -Bgcctestdir -Wl,-R,. -Wl,-z,relro -Wl,-z,now
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_now_test_LDADD = relro_now_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_strip_test_SOURCES = relro_test_main.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_strip_test_DEPENDENCIES = gcctestdir/ld relro_strip_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_strip_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
@ -2905,6 +2916,9 @@ protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES)
protected_2$(EXEEXT): $(protected_2_OBJECTS) $(protected_2_DEPENDENCIES)
@rm -f protected_2$(EXEEXT)
$(protected_2_LINK) $(protected_2_OBJECTS) $(protected_2_LDADD) $(LIBS)
relro_now_test$(EXEEXT): $(relro_now_test_OBJECTS) $(relro_now_test_DEPENDENCIES)
@rm -f relro_now_test$(EXEEXT)
$(relro_now_test_LINK) $(relro_now_test_OBJECTS) $(relro_now_test_LDADD) $(LIBS)
relro_script_test$(EXEEXT): $(relro_script_test_OBJECTS) $(relro_script_test_DEPENDENCIES)
@rm -f relro_script_test$(EXEEXT)
$(relro_script_test_LINK) $(relro_script_test_OBJECTS) $(relro_script_test_LDADD) $(LIBS)
@ -3744,6 +3758,8 @@ protected_2.log: protected_2$(EXEEXT)
@p='protected_2$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
relro_test.log: relro_test$(EXEEXT)
@p='relro_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
relro_now_test.log: relro_now_test$(EXEEXT)
@p='relro_now_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
relro_strip_test.log: relro_strip_test$(EXEEXT)
@p='relro_strip_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
relro_script_test.log: relro_script_test$(EXEEXT)
@ -4476,6 +4492,8 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test.stdout: relro_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -SlW relro_test.so > relro_test.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_now_test.so: gcctestdir/ld relro_test_pic.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro -Wl,-z,now relro_test_pic.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_strip_test.so: relro_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_STRIP) -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test.so: gcctestdir/ld relro_script_test.t relro_test_pic.o

View File

@ -834,26 +834,39 @@ Target_x86_64::got_section(Symbol_table* symtab, Layout* layout)
{
gold_assert(symtab != NULL && layout != NULL);
// When using -z now, we can treat .got.plt as a relro section.
// Without -z now, it is modified after program startup by lazy
// PLT relocations.
bool is_got_plt_relro = parameters->options().now();
Output_section_order got_order = (is_got_plt_relro
? ORDER_RELRO
: ORDER_RELRO_LAST);
Output_section_order got_plt_order = (is_got_plt_relro
? ORDER_RELRO
: ORDER_NON_RELRO_FIRST);
this->got_ = new Output_data_got<64, false>();
layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_, ORDER_RELRO_LAST,
true);
this->got_, got_order, true);
this->got_plt_ = new Output_data_space(8, "** GOT PLT");
layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_plt_, ORDER_NON_RELRO_FIRST,
false);
this->got_plt_, got_plt_order,
is_got_plt_relro);
// The first three entries are reserved.
this->got_plt_->set_current_data_size(3 * 8);
// Those bytes can go into the relro segment.
layout->increase_relro(3 * 8);
if (!is_got_plt_relro)
{
// Those bytes can go into the relro segment.
layout->increase_relro(3 * 8);
}
// Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
this->global_offset_table_ =
@ -872,7 +885,7 @@ Target_x86_64::got_section(Symbol_table* symtab, Layout* layout)
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_irelative_,
ORDER_NON_RELRO_FIRST, false);
got_plt_order, is_got_plt_relro);
// If there are any TLSDESC relocations, they get GOT entries in
// .got.plt after the jump slot and IRELATIVE entries.
@ -881,7 +894,7 @@ Target_x86_64::got_section(Symbol_table* symtab, Layout* layout)
(elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE),
this->got_tlsdesc_,
ORDER_NON_RELRO_FIRST, false);
got_plt_order, is_got_plt_relro);
}
return this->got_;