diff options
author | Ian Lance Taylor <ian@airs.com> | 2008-08-13 07:37:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2008-08-13 07:37:46 +0000 |
commit | 2d924fd9ebc6a97f9ef93208597e563c88f5e9e8 (patch) | |
tree | ecbfc504dee9ce3475f988e5bce567d070e0c0c1 /gold/testsuite | |
parent | 9e9a97982d36c9b5e6b3d79ecbaf68041981e23b (diff) | |
download | gdb-2d924fd9ebc6a97f9ef93208597e563c88f5e9e8.zip gdb-2d924fd9ebc6a97f9ef93208597e563c88f5e9e8.tar.gz gdb-2d924fd9ebc6a97f9ef93208597e563c88f5e9e8.tar.bz2 |
* layout.cc (Layout::attach_allocated_section_to_segment): Don't
set tls_segment_ or relro_segment_.
(Layout::make_output_segment): Set tls_segment_ and relro_segment_
when appropriate.
* output.h (Output_section::clear_is_relro): New function.
* output.cc (Output_segment::add_output_section): Handle SHF_TLS
sections specially even when output_data_ is empty.
(Output_segment::maximum_alignment): When first section is relro,
only force alignment for PT_LOAD segments.
* script.cc (script_data_segment_align): New function.
(script_data_segment_relro_end): New function.
* script-c.h (script_data_segment_align): Declare.
(script_data_segment_relro_end): Declare.
* script-sections.h (class Script_sections): Declare
data_segment_align and data_segment_relro_end. Add fields
segment_align_index_ and saw_relro_end_.
* script-sections.cc (class Sections_element): Add set_is_relro
virtual function. Add new bool* parameter to place_orphan_here.
Add get_output_section virtual function.
(class Output_section_definition): Add set_is_relro. Add new
bool* parameter to place_orphan_here. Add get_output_section.
Add is_relro_ field.
(Output_section_definition::Output_section_definition): Initialize
evaluated_address_, evaluated_load_address, evaluated_addralign_,
and is_relro_ fields.
(Output_section_definition::place_orphan_here): Add is_relro
parameter.
(Output_section_definition::set_section_addresses): Set relro for
output section.
(Output_section_definition::alternate_constraint): Likewise.
(class Orphan_output_section): Add new bool* parameter to
place_orphan_here. Add get_output_section.
(Orphan_output_section::place_orphan_here): Add is_relro
parameter.
(Script_sections::Script_sections): Initialize
data_segment_align_index_ and saw_relro_end_.
(Script_sections::data_segment_align): New function.
(Script_sections::data_segment_relro_end): New function.
(Script_sections::place_orphan): Set or clear is_relro.
(Script_sections::set_section_addresses): Force alignment of first
TLS section.
* yyscript.y (exp): Call script_data_segment_align and
script_data_segment_relro_end.
* testsuite/relro_script_test.t: New file.
* testsuite/relro_test.cc (using_script): Declare.
(t1, t2): Test using_script.
* testsuite/Makefile.am (check_PROGRAMS): Add relro_script_test.
(relro_script_test_SOURCES): Define.
(relro_script_test_DEPENDENCIES): Define.
(relro_script_test_LDFLAGS): Define.
(relro_script_test_LDADD): Define.
(relro_script_test.so): New target.
* testsuite/Makefile.in: Rebuild.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 8 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 32 | ||||
-rw-r--r-- | gold/testsuite/relro_script_test.t | 52 | ||||
-rw-r--r-- | gold/testsuite/relro_test.cc | 11 |
4 files changed, 96 insertions, 7 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index df98677..c9dd470 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -835,6 +835,14 @@ relro_test.so: gcctestdir/ld relro_test_pic.o relro_test_pic.o: relro_test.cc $(CXXCOMPILE) -c -fpic -o $@ $< +check_PROGRAMS += relro_script_test +relro_script_test_SOURCES = relro_test_main.cc +relro_script_test_DEPENDENCIES = gcctestdir/ld relro_script_test.so +relro_script_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +relro_script_test_LDADD = relro_script_test.so +relro_script_test.so: gcctestdir/ld relro_script_test.t relro_test_pic.o + $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro -T $(srcdir)/relro_script_test.t relro_test_pic.o + check_PROGRAMS += script_test_1 script_test_1_SOURCES = script_test_1.cc script_test_1_DEPENDENCIES = gcctestdir/ld script_test_1.t diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index c5e929a..9f72b88 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -229,9 +229,10 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_19 = ver_test ver_test_2 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_6 ver_test_8 ver_test_9 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1 protected_2 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test script_test_1 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test script_test_3 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test relro_script_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1 script_test_2 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ justsyms binary_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3 @GCC_FALSE@script_test_1_DEPENDENCIES = libgoldtest.a ../libgold.a \ @GCC_FALSE@ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ @GCC_FALSE@ $(am__DEPENDENCIES_1) @@ -351,6 +352,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_script_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ justsyms$(EXEEXT) \ @@ -523,6 +525,10 @@ am__protected_2_SOURCES_DIST = protected_main_1.cc protected_3.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_1.$(OBJEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_3.$(OBJEXT) protected_2_OBJECTS = $(am_protected_2_OBJECTS) +am__relro_script_test_SOURCES_DIST = relro_test_main.cc +@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) am__relro_test_SOURCES_DIST = relro_test_main.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_test_OBJECTS = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT) @@ -783,9 +789,10 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(initpri1_SOURCES) $(justsyms_SOURCES) many_sections_r_test.c \ $(many_sections_test_SOURCES) $(object_unittest_SOURCES) \ $(protected_1_SOURCES) $(protected_2_SOURCES) \ - $(relro_test_SOURCES) $(script_test_1_SOURCES) \ - $(script_test_2_SOURCES) script_test_3.c \ - $(tls_pic_test_SOURCES) $(tls_shared_gd_to_ie_test_SOURCES) \ + $(relro_script_test_SOURCES) $(relro_test_SOURCES) \ + $(script_test_1_SOURCES) $(script_test_2_SOURCES) \ + script_test_3.c $(tls_pic_test_SOURCES) \ + $(tls_shared_gd_to_ie_test_SOURCES) \ $(tls_shared_gnu2_gd_to_ie_test_SOURCES) \ $(tls_shared_gnu2_test_SOURCES) $(tls_shared_ie_test_SOURCES) \ $(tls_shared_nonpic_test_SOURCES) $(tls_shared_test_SOURCES) \ @@ -832,7 +839,9 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(am__initpri1_SOURCES_DIST) $(am__justsyms_SOURCES_DIST) \ many_sections_r_test.c $(am__many_sections_test_SOURCES_DIST) \ $(object_unittest_SOURCES) $(am__protected_1_SOURCES_DIST) \ - $(am__protected_2_SOURCES_DIST) $(am__relro_test_SOURCES_DIST) \ + $(am__protected_2_SOURCES_DIST) \ + $(am__relro_script_test_SOURCES_DIST) \ + $(am__relro_test_SOURCES_DIST) \ $(am__script_test_1_SOURCES_DIST) \ $(am__script_test_2_SOURCES_DIST) script_test_3.c \ $(am__tls_pic_test_SOURCES_DIST) \ @@ -1341,6 +1350,10 @@ binary_unittest_SOURCES = binary_unittest.cc @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_script_test_SOURCES = relro_test_main.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_DEPENDENCIES = gcctestdir/ld relro_script_test.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_LDADD = relro_script_test.so @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_SOURCES = script_test_1.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_DEPENDENCIES = gcctestdir/ld script_test_1.t @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_LDFLAGS = -Bgcctestdir/ -Wl,-R,. -T $(srcdir)/script_test_1.t @@ -1508,6 +1521,9 @@ protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES) protected_2$(EXEEXT): $(protected_2_OBJECTS) $(protected_2_DEPENDENCIES) @rm -f protected_2$(EXEEXT) $(CXXLINK) $(protected_2_LDFLAGS) $(protected_2_OBJECTS) $(protected_2_LDADD) $(LIBS) +relro_script_test$(EXEEXT): $(relro_script_test_OBJECTS) $(relro_script_test_DEPENDENCIES) + @rm -f relro_script_test$(EXEEXT) + $(CXXLINK) $(relro_script_test_LDFLAGS) $(relro_script_test_OBJECTS) $(relro_script_test_LDADD) $(LIBS) relro_test$(EXEEXT): $(relro_test_OBJECTS) $(relro_test_DEPENDENCIES) @rm -f relro_test$(EXEEXT) $(CXXLINK) $(relro_test_LDFLAGS) $(relro_test_OBJECTS) $(relro_test_LDADD) $(LIBS) @@ -2274,6 +2290,8 @@ uninstall-am: uninstall-info-am @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro relro_test_pic.o @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_pic.o: relro_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test.so: gcctestdir/ld relro_script_test.t relro_test_pic.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro -T $(srcdir)/relro_script_test.t relro_test_pic.o @GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_2.o: justsyms_2.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_2r.o: justsyms_2.o gcctestdir/ld $(srcdir)/justsyms.t diff --git a/gold/testsuite/relro_script_test.t b/gold/testsuite/relro_script_test.t new file mode 100644 index 0000000..cacb84d --- /dev/null +++ b/gold/testsuite/relro_script_test.t @@ -0,0 +1,52 @@ +/* relro_test.t -- relro script test for gold + + Copyright 2008 Free Software Foundation, Inc. + Written by Ian Lance Taylor <iant@google.com>. + + This file is part of gold. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +/* With luck this will work on all platforms. */ + +using_script = 1; + +SECTIONS +{ + . = SIZEOF_HEADERS; + + .text : { *(.text) } + + .eh_frame : ONLY_IF_RO { KEEP(*(.eh_frame)) } + + . = (ALIGN(CONSTANT(MAXPAGESIZE)) + - ((CONSTANT(MAXPAGESIZE) - .) & (CONSTANT(MAXPAGESIZE) - 1))); + . = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE)); + + .eh_frame : ONLY_IF_RW { KEEP(*(.eh_frame)) } + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) + *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got) } + + . = DATA_SEGMENT_RELRO_END(0, .); + + .data : { *(.data .data.* .gnu.linkonce.d.*) } + + . = DATA_SEGMENT_END (.); +} diff --git a/gold/testsuite/relro_test.cc b/gold/testsuite/relro_test.cc index 1fc1b43..bc6c77b 100644 --- a/gold/testsuite/relro_test.cc +++ b/gold/testsuite/relro_test.cc @@ -28,6 +28,11 @@ #include <stdint.h> #include <unistd.h> +// This tests we were linked with a script. If we were linked with a +// script, relro currently does not work. + +extern char using_script[] __attribute__ ((weak)); + // This code is put into a shared library linked with -z relro. // i1 and i2 are not relro variables. @@ -45,6 +50,9 @@ int* const p2 = &i2; bool t1() { + if (using_script) + return true; + void* i1addr = static_cast<void*>(&i1); void* i2addr = static_cast<void*>(&i2); const void* p1addr = static_cast<const void*>(&p1); @@ -129,6 +137,9 @@ f2() bool t2() { + if (using_script) + return true; + signal(SIGSEGV, sigsegv_handler); orig_terminate = std::set_terminate(terminate_handler); |