* output.cc (Output_segment::set_offset): Search for the first and
	last sections rather than assuming that the list is in order.
	(Output_segment::find_first_and_last_list): New function.
	* output.h (class Output_segment): Update declarations.
	* testsuite/Makefile.am (check_PROGRAMS): Add relro_strip_test.
	(relro_strip_test_SOURCES): New variable.
	(relro_strip_test_DEPENDENCIES): New variable.
	(relro_strip_test_LDFLAGS): New variable.
	(relro_strip_test_LDADD): New variable.
	(relro_strip_test.so): New target.
This commit is contained in:
Ian Lance Taylor 2010-08-02 11:59:11 +00:00
parent 85cfcbfb1a
commit 5f1ab67afc
5 changed files with 94 additions and 20 deletions

View File

@ -1,3 +1,17 @@
2010-08-02 Ian Lance Taylor <iant@google.com>
PR 11866
* output.cc (Output_segment::set_offset): Search for the first and
last sections rather than assuming that the list is in order.
(Output_segment::find_first_and_last_list): New function.
* output.h (class Output_segment): Update declarations.
* testsuite/Makefile.am (check_PROGRAMS): Add relro_strip_test.
(relro_strip_test_SOURCES): New variable.
(relro_strip_test_DEPENDENCIES): New variable.
(relro_strip_test_LDFLAGS): New variable.
(relro_strip_test_LDADD): New variable.
(relro_strip_test.so): New target.
2010-08-02 Ian Lance Taylor <iant@google.com> 2010-08-02 Ian Lance Taylor <iant@google.com>
* i386.cc (class Target_i386): Add got_tlsdesc_ field. * i386.cc (class Target_i386): Add got_tlsdesc_ field.

View File

@ -4042,11 +4042,14 @@ Output_segment::set_offset(unsigned int increase)
return; return;
} }
const Output_data* first; // Find the first and last section by address. The sections may
if (this->output_data_.empty()) // have been sorted for the PT_LOAD segment.
first = this->output_bss_.front(); const Output_data* first = NULL;
else const Output_data* last_data = NULL;
first = this->output_data_.front(); const Output_data* last_bss = NULL;
this->find_first_and_last_list(&this->output_data_, &first, &last_data);
this->find_first_and_last_list(&this->output_bss_, &first, &last_bss);
this->vaddr_ = first->address(); this->vaddr_ = first->address();
this->paddr_ = (first->has_load_address() this->paddr_ = (first->has_load_address()
? first->load_address() ? first->load_address()
@ -4057,18 +4060,11 @@ Output_segment::set_offset(unsigned int increase)
if (this->output_data_.empty()) if (this->output_data_.empty())
this->filesz_ = 0; this->filesz_ = 0;
else else
{ this->filesz_ = (last_data->address()
const Output_data* last_data = this->output_data_.back(); + last_data->data_size()
this->filesz_ = (last_data->address() - this->vaddr_);
+ last_data->data_size()
- this->vaddr_);
}
const Output_data* last; const Output_data* last = last_bss != NULL ? last_bss : last_data;
if (this->output_bss_.empty())
last = this->output_data_.back();
else
last = this->output_bss_.back();
this->memsz_ = (last->address() this->memsz_ = (last->address()
+ last->data_size() + last->data_size()
- this->vaddr_); - this->vaddr_);
@ -4087,6 +4083,37 @@ Output_segment::set_offset(unsigned int increase)
} }
} }
// Look through a list of Output_data objects and find the first and
// last by address.
void
Output_segment::find_first_and_last_list(const Output_data_list* pdl,
const Output_data** pfirst,
const Output_data** plast) const
{
const Output_data* first = *pfirst;
const Output_data* last = *plast;
for (Output_data_list::const_iterator p = pdl->begin(); p != pdl->end(); ++p)
{
if (first == NULL
|| (*p)->address() < first->address()
|| ((*p)->address() == first->address()
&& (*p)->data_size() < first->data_size()))
{
first = *p;
*pfirst = first;
}
if (last == NULL
|| (*p)->address() > last->address()
|| ((*p)->address() == last->address()
&& (*p)->data_size() > last->data_size()))
{
last = *p;
*plast = last;
}
}
}
// Set the TLS offsets of the sections in the PT_TLS segment. // Set the TLS offsets of the sections in the PT_TLS segment.
void void

View File

@ -4023,6 +4023,12 @@ class Output_segment
Output_section** found, Output_section** found,
uint64_t* found_lma) const; uint64_t* found_lma) const;
// Find the first and last entries by address.
void
find_first_and_last_list(const Output_data_list* pdl,
const Output_data** pfirst,
const Output_data** plast) const;
// Write the section headers in the list into V. // Write the section headers in the list into V.
template<int size, bool big_endian> template<int size, bool big_endian>
unsigned char* unsigned char*

View File

@ -1078,6 +1078,14 @@ relro_test.so: gcctestdir/ld relro_test_pic.o
relro_test_pic.o: relro_test.cc relro_test_pic.o: relro_test.cc
$(CXXCOMPILE) -c -fpic -o $@ $< $(CXXCOMPILE) -c -fpic -o $@ $<
check_PROGRAMS += relro_strip_test
relro_strip_test_SOURCES = relro_test_main.cc
relro_strip_test_DEPENDENCIES = gcctestdir/ld relro_strip_test.so
relro_strip_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
relro_strip_test_LDADD = relro_strip_test.so
relro_strip_test.so: relro_test.so
$(TEST_STRIP) -o $@ $<
check_PROGRAMS += relro_script_test check_PROGRAMS += relro_script_test
relro_script_test_SOURCES = relro_test_main.cc relro_script_test_SOURCES = relro_test_main.cc
relro_script_test_DEPENDENCIES = gcctestdir/ld relro_script_test.so relro_script_test_DEPENDENCIES = gcctestdir/ld relro_script_test.so

View File

@ -236,6 +236,7 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_6 ver_test_8 ver_test_9 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_6 ver_test_8 ver_test_9 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11 protected_1 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11 protected_1 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2 relro_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2 relro_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@ relro_script_test script_test_1 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test script_test_3 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test script_test_3 \
@ -496,6 +497,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_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@ relro_script_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2$(EXEEXT) \
@ -795,6 +797,11 @@ protected_2_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
relro_script_test_OBJECTS = $(am_relro_script_test_OBJECTS) relro_script_test_OBJECTS = $(am_relro_script_test_OBJECTS)
relro_script_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ relro_script_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(relro_script_test_LDFLAGS) $(LDFLAGS) -o $@ $(relro_script_test_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_strip_test_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT)
relro_strip_test_OBJECTS = $(am_relro_strip_test_OBJECTS)
relro_strip_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(relro_strip_test_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_test_OBJECTS = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@am_relro_test_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test_main.$(OBJEXT)
relro_test_OBJECTS = $(am_relro_test_OBJECTS) relro_test_OBJECTS = $(am_relro_test_OBJECTS)
@ -1141,10 +1148,11 @@ 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_2.c plugin_test_3.c plugin_test_4.c \
plugin_test_5.c plugin_test_6.c plugin_test_7.c \ plugin_test_5.c plugin_test_6.c plugin_test_7.c \
plugin_test_8.c $(protected_1_SOURCES) $(protected_2_SOURCES) \ plugin_test_8.c $(protected_1_SOURCES) $(protected_2_SOURCES) \
$(relro_script_test_SOURCES) $(relro_test_SOURCES) \ $(relro_script_test_SOURCES) $(relro_strip_test_SOURCES) \
$(script_test_1_SOURCES) $(script_test_2_SOURCES) \ $(relro_test_SOURCES) $(script_test_1_SOURCES) \
script_test_3.c $(searched_file_test_SOURCES) \ $(script_test_2_SOURCES) script_test_3.c \
$(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \ $(searched_file_test_SOURCES) $(thin_archive_test_1_SOURCES) \
$(thin_archive_test_2_SOURCES) \
$(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \ $(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \
tls_pie_pic_test.c tls_pie_test.c $(tls_script_test_SOURCES) \ tls_pie_pic_test.c tls_pie_test.c $(tls_script_test_SOURCES) \
$(tls_shared_gd_to_ie_test_SOURCES) \ $(tls_shared_gd_to_ie_test_SOURCES) \
@ -1739,6 +1747,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_DEPENDENCIES = gcctestdir/ld relro_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. @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_test_LDADD = relro_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,.
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_strip_test_LDADD = relro_strip_test.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_SOURCES = relro_test_main.cc @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_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_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
@ -2066,6 +2078,9 @@ protected_2$(EXEEXT): $(protected_2_OBJECTS) $(protected_2_DEPENDENCIES)
relro_script_test$(EXEEXT): $(relro_script_test_OBJECTS) $(relro_script_test_DEPENDENCIES) relro_script_test$(EXEEXT): $(relro_script_test_OBJECTS) $(relro_script_test_DEPENDENCIES)
@rm -f relro_script_test$(EXEEXT) @rm -f relro_script_test$(EXEEXT)
$(relro_script_test_LINK) $(relro_script_test_OBJECTS) $(relro_script_test_LDADD) $(LIBS) $(relro_script_test_LINK) $(relro_script_test_OBJECTS) $(relro_script_test_LDADD) $(LIBS)
relro_strip_test$(EXEEXT): $(relro_strip_test_OBJECTS) $(relro_strip_test_DEPENDENCIES)
@rm -f relro_strip_test$(EXEEXT)
$(relro_strip_test_LINK) $(relro_strip_test_OBJECTS) $(relro_strip_test_LDADD) $(LIBS)
relro_test$(EXEEXT): $(relro_test_OBJECTS) $(relro_test_DEPENDENCIES) relro_test$(EXEEXT): $(relro_test_OBJECTS) $(relro_test_DEPENDENCIES)
@rm -f relro_test$(EXEEXT) @rm -f relro_test$(EXEEXT)
$(relro_test_LINK) $(relro_test_OBJECTS) $(relro_test_LDADD) $(LIBS) $(relro_test_LINK) $(relro_test_OBJECTS) $(relro_test_LDADD) $(LIBS)
@ -2812,6 +2827,8 @@ protected_2.log: protected_2$(EXEEXT)
@p='protected_2$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='protected_2$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
relro_test.log: relro_test$(EXEEXT) relro_test.log: relro_test$(EXEEXT)
@p='relro_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='relro_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) relro_script_test.log: relro_script_test$(EXEEXT)
@p='relro_script_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='relro_script_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
script_test_1.log: script_test_1$(EXEEXT) script_test_1.log: script_test_1$(EXEEXT)
@ -3428,6 +3445,8 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro relro_test_pic.o @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@relro_test_pic.o: relro_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -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 @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@ $(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@justsyms_2.o: justsyms_2.cc