From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11442 invoked by alias); 12 Oct 2010 19:24:29 -0000 Received: (qmail 11432 invoked by uid 22791); 12 Oct 2010 19:24:27 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD,T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Oct 2010 19:24:20 +0000 Received: from kpbe13.cbf.corp.google.com (kpbe13.cbf.corp.google.com [172.25.105.77]) by smtp-out.google.com with ESMTP id o9CJOIAK009218 for ; Tue, 12 Oct 2010 12:24:18 -0700 Received: from pvg16 (pvg16.prod.google.com [10.241.210.144]) by kpbe13.cbf.corp.google.com with ESMTP id o9CJOH0r014080 for ; Tue, 12 Oct 2010 12:24:17 -0700 Received: by pvg16 with SMTP id 16so277260pvg.31 for ; Tue, 12 Oct 2010 12:24:17 -0700 (PDT) Received: by 10.143.8.3 with SMTP id l3mr6780646wfi.125.1286911453529; Tue, 12 Oct 2010 12:24:13 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-123-203.mtv.corp.google.com [172.22.123.203]) by mx.google.com with ESMTPS id e36sm6101934wfj.14.2010.10.12.12.24.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 12 Oct 2010 12:24:12 -0700 (PDT) From: Ian Lance Taylor To: Cc: binutils Subject: Re: [GOLD][PATCH] Fix a sort order breakage of the zero-length script output sections. References: <1286572778.1642.3200.camel@dp690-dev5v11.accesssoftek.com> Date: Tue, 12 Oct 2010 19:24:00 -0000 In-Reply-To: <1286572778.1642.3200.camel@dp690-dev5v11.accesssoftek.com> (Viktor Kutuzov's message of "Fri, 8 Oct 2010 14:19:38 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00197.txt.bz2 --=-=-= Content-length: 1876 Viktor Kutuzov writes: > * configure.ac: Add NATIVE_OR_CROSS_LINKER condition macro. > * configure: Regenerate. > * testsuite/Makefile.am: Wrap the cross linker tests and the common > tests into NATIVE_OR_CROSS_LINKER; > Add the script section order test. > * testsuite/Makefile.in: Regenerate. > * testsuite/script_test_10.sh: New test. Test script section > order. > * testsuite/script_test_10.t: Likewise. > * testsuite/script_test_10.s: Likewise. > * script-sections.h (Script_sections): Sections_elements as public; > Add a new member to save a list of the section elements. > (Sort_output_sections::ctor): Add new parameter to pass a list > of the section elements. > * script-sections.cc (Sort_output_sections::swap): New method. Approved and applied with some changes to script-sections.cc and testsuite/Makefile.am, as follows. Thanks. Ian 2010-10-12 Viktor Kutuzov * script-sections.h (class Script_sections): Make Sections_elements typedef public. * script-sections.cc (class Sort_output_sections): Add elements_ field. Add constructor which sets it; change all callers. (Sort_output_sections::is_before): New function. (Sort_output_sections::operator()): Call is_before. * configure.ac (NATIVE_OR_CROSS_LINKER): New automake conditional. * testsuite/script_test_10.sh: New test. Test script section order. * testsuite/script_test_10.t: Likewise. * testsuite/script_test_10.s: Likewise. * testsuite/Makefile.am: Wrap the cross linker tests and the common tests into NATIVE_OR_CROSS_LINKER. (check_SCRIPTS): Add script_test_10.sh. (check_DATA): Add script_test_10.stdout. (script_test_10.o, script_test_10): New targets. (script_test_10.stdout): New target. * configure, testsuite/Makefile.in: Regenerate. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=foo.patch Content-Description: changes Content-length: 3816 Index: script-sections.cc =================================================================== RCS file: /cvs/src/src/gold/script-sections.cc,v retrieving revision 1.44 diff -p -u -r1.44 script-sections.cc --- script-sections.cc 6 Oct 2010 08:58:57 -0000 1.44 +++ script-sections.cc 12 Oct 2010 19:21:23 -0000 @@ -3552,8 +3552,19 @@ Script_sections::set_section_addresses(S class Sort_output_sections { public: + Sort_output_sections(const Script_sections::Sections_elements* elements) + : elements_(elements) + { } + bool operator()(const Output_section* os1, const Output_section* os2) const; + + private: + bool + is_before(const Output_section* os1, const Output_section* os2) const; + + private: + const Script_sections::Sections_elements* elements_; }; bool @@ -3592,7 +3603,36 @@ Sort_output_sections::operator()(const O if (!os1->is_noload() && os2->is_noload()) return true; - // Otherwise we don't care. + // The sections have the same address. Check the section positions + // in accordance with the linker script. + return this->is_before(os1, os2); +} + +// Return true if OS1 comes before OS2 in ELEMENTS_. This ensures +// that we keep empty sections in the order in which they appear in a +// linker script. + +bool +Sort_output_sections::is_before(const Output_section* os1, + const Output_section* os2) const +{ + if (this->elements_ == NULL) + return false; + + for (Script_sections::Sections_elements::const_iterator + p = this->elements_->begin(); + p != this->elements_->end(); + ++p) + { + if (os1 == (*p)->get_output_section()) + { + for (++p; p != this->elements_->end(); ++p) + if (os2 == (*p)->get_output_section()) + return true; + break; + } + } + return false; } @@ -3666,7 +3706,8 @@ Script_sections::create_segments(Layout* layout->get_allocated_sections(§ions); // Sort the sections by address. - std::stable_sort(sections.begin(), sections.end(), Sort_output_sections()); + std::stable_sort(sections.begin(), sections.end(), + Sort_output_sections(this->sections_elements_)); this->create_note_and_tls_segments(layout, §ions); Index: testsuite/Makefile.am =================================================================== RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v retrieving revision 1.148 diff -p -u -r1.148 Makefile.am --- testsuite/Makefile.am 18 Sep 2010 00:34:58 -0000 1.148 +++ testsuite/Makefile.am 12 Oct 2010 19:21:23 -0000 @@ -70,12 +70,14 @@ LDADD = libgoldtest.a ../libgold.a ../.. # The unittests themselves +if NATIVE_OR_CROSS_LINKER check_PROGRAMS += object_unittest object_unittest_SOURCES = object_unittest.cc check_PROGRAMS += binary_unittest binary_unittest_SOURCES = binary_unittest.cc +endif NATIVE_OR_CROSS_LINKER # --------------------------------------------------------------------- # These tests test the output of gold (end-to-end tests). In @@ -1798,7 +1800,21 @@ memory_test.stdout: memory_test endif GCC endif NATIVE_LINKER -# These tests work with cross linkers. +# These tests work with native and cross linkers. + +if NATIVE_OR_CROSS_LINKER + +# Test script section order. +check_SCRIPTS += script_test_10.sh +check_DATA += script_test_10.stdout +script_test_10.o: script_test_10.s + $(TEST_AS) -o $@ $< +script_test_10: $(srcdir)/script_test_10.t script_test_10.o gcctestdir/ld + gcctestdir/ld -o $@ script_test_10.o -T $(srcdir)/script_test_10.t +script_test_10.stdout: script_test_10 + $(TEST_READELF) -SW script_test_10 > $@ + +# These tests work with cross linkers only. if DEFAULT_TARGET_I386 @@ -2131,3 +2147,6 @@ MOSTLYCLEANFILES += arm_cortex_a8_b_cond arm_cortex_a8_blx arm_cortex_a8_local arm_cortex_a8_local_reloc endif DEFAULT_TARGET_ARM + +endif NATIVE_OR_CROSS_LINKER + --=-=-=--