From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49009 invoked by alias); 28 Mar 2015 22:46:53 -0000 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 Received: (qmail 48995 invoked by uid 89); 28 Mar 2015 22:46:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-oi0-f44.google.com Received: from mail-oi0-f44.google.com (HELO mail-oi0-f44.google.com) (209.85.218.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 28 Mar 2015 22:46:51 +0000 Received: by oifl3 with SMTP id l3so101987499oif.0 for ; Sat, 28 Mar 2015 15:46:49 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.46.129 with SMTP id v1mr19840609obm.22.1427582809357; Sat, 28 Mar 2015 15:46:49 -0700 (PDT) Received: by 10.76.134.102 with HTTP; Sat, 28 Mar 2015 15:46:49 -0700 (PDT) In-Reply-To: References: <20150319130244.GA22592@intel.com> <20150326022246.GU26234@bubble.grove.modra.org> <20150328041540.GE26234@bubble.grove.modra.org> Date: Sat, 28 Mar 2015 22:46:00 -0000 Message-ID: Subject: Re: [PATCH] Reduce file size for PT_GNU_RELRO segment From: "H.J. Lu" To: Binutils Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00427.txt.bz2 On Sat, Mar 28, 2015 at 11:30 AM, H.J. Lu wrote: > On Fri, Mar 27, 2015 at 9:15 PM, Alan Modra wrote: >> On Fri, Mar 27, 2015 at 01:00:20PM -0700, H.J. Lu wrote: >>> On Wed, Mar 25, 2015 at 7:22 PM, Alan Modra wrote: >>> > Isn't this just re-inventing the commonpage adjustment done for >>> > DATA_SEGMENT_ALIGN? Why didn't the existing code in ldexp.c work for >>> > you? >>> >>> segment. In order to properly align PT_GNU_RELRO segmnet, we pad the first >>> section of PT_GNU_RELRO segment by >> >> Adjusting the start of the first section of the PT_GNU_RELRO segment >> is exactly what DATA_SEGMENT_ALIGN is supposed to do. You are >> patching the wrong place. Any adjustment to the start of the relro >> segment belongs in ldexp.c code evaluating DATA_SEGMENT_ALIGN. >> > > Since output_section_statement isn't passed to ldexp.c, I don't see how > DATA_SEGMENT_ALIGN in ldexp.c can check the section address and size. > > lang_size_sections aligns expld.dataseg.base: 5422 /* Aligning the adjusted base guarantees the padding 5423 between sections won't change. This is better than 5424 simply subtracting 1 << max_alignment_power which is 5425 what we used to do here. */ 5426 expld.dataseg.base &= ~((1 << max_alignment_power) - 1); 5427 lang_reset_memory_regions (); 5428 one_lang_size_sections_pass (relax, check_regions); 5429 } 5430 } 5431 link_info.relro_start = expld.dataseg.base; (gdb) p/x expld.dataseg $290 = {phase = 0x4, base = 0x24bd00, min_base = 0x4bcc7, relro_end = 0x24f000, end = 0x64eae0, pagesize = 0x1000, maxpagesize = 0x200000, relro = 0x0, relro_start_stat = 0x8203e0, relro_end_stat = 0x822b20} (gdb) and calls lang_size_sections_1 to align the first section of PT_GNU_RELRO segmnet: (gdb) bt #0 lang_size_sections_1 (prev=0x81f258, output_section_statement=0x8135b0, fill=0x0, dot=2407680, relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:4919 #1 0x0000000000415219 in one_lang_size_sections_pass (relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5368 #2 0x000000000041541d in lang_size_sections (relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5428 #3 0x0000000000417758 in lang_process () at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6766 #4 0x000000000041b588 in main (argc=74, argv=0x7fffffffd328) at /export/gnu/import/git/sources/binutils-gdb/ld/ldmain.c:419 (gdb) list 4914 if (section_alignment > 0) 4915 { 4916 bfd_vma savedot = newdot; 4917 newdot = align_power (newdot, section_alignment); 4918 4919 dotdelta = newdot - savedot; 4920 if (dotdelta != 0 4921 && (config.warn_section_align 4922 || os->addr_tree != NULL) 4923 && expld.phase != lang_mark_phase_enum) (gdb) After that, DATA_SEGMENT_ALIGN is processed: (gdb) bt #0 fold_binary (tree=0x820380) at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:570 #1 0x000000000042065d in exp_fold_tree_1 (tree=0x820380) at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:989 #2 0x00000000004206f2 in exp_fold_tree_1 (tree=0x8203b0) at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:1008 #3 0x0000000000420bef in exp_fold_tree (tree=0x8203b0, current_section=0x8078b0 <_bfd_std_section+560>, dotp=0x7fffffffcf68) at /export/gnu/import/git/sources/binutils-gdb/ld/ldexp.c:1166 #4 0x0000000000414e36 in lang_size_sections_1 (prev=0x820300, output_section_statement=0x8135b0, fill=0x0, dot=310471, relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5211 #5 0x0000000000415219 in one_lang_size_sections_pass (relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5368 #6 0x000000000041524f in lang_size_sections (relax=0x0, check_regions=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:5378 #7 0x000000000041724a in lang_relax_sections (need_layout=1) at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6529 #8 0x0000000000427d83 in gldelf_x86_64_map_segments (need_layout=1) at eelf_x86_64.c:68 #9 0x000000000042ae3f in gldelf_x86_64_after_allocation () ---Type to continue, or q to quit--- at eelf_x86_64.c:1787 #10 0x0000000000421899 in ldemul_after_allocation () at /export/gnu/import/git/sources/binutils-gdb/ld/ldemul.c:70 #11 0x000000000041775d in lang_process () at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6770 #12 0x000000000041b588 in main (argc=74, argv=0x7fffffffd328) at /export/gnu/import/git/sources/binutils-gdb/ld/ldmain.c:419 (gdb) list 565 else if (expld.dataseg.phase == exp_dataseg_none) 566 { 567 expld.dataseg.phase = exp_dataseg_align_seen; 568 expld.dataseg.min_base = expld.dot; 569 expld.dataseg.base = expld.result.value; 570 expld.dataseg.pagesize = commonpage; 571 expld.dataseg.maxpagesize = maxpage; 572 expld.dataseg.relro_end = 0; 573 } 574 else (gdb) f 11 #11 0x000000000041775d in lang_process () at /export/gnu/import/git/sources/binutils-gdb/ld/ldlang.c:6770 6770 ldemul_after_allocation (); (gdb) list 6765 /* Size up the sections. */ 6766 lang_size_sections (NULL, ! RELAXATION_ENABLED); 6767 6768 /* See if anything special should be done now we know how big 6769 everything is. This is where relaxation is done. */ 6770 ldemul_after_allocation (); 6771 6772 /* Fix any .startof. or .sizeof. symbols. */ 6773 lang_set_startof (); 6774 (gdb) I don't see DATA_SEGMENT_ALIGN changes section address. -- H.J.