From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8667 invoked by alias); 30 Aug 2009 05:42:39 -0000 Received: (qmail 8653 invoked by uid 22791); 30 Aug 2009 05:42:35 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from nschwmtas04p.mx.bigpond.com (HELO nschwmtas04p.mx.bigpond.com) (61.9.189.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Aug 2009 05:42:27 +0000 Received: from nschwotgx01p.mx.bigpond.com ([121.209.33.16]) by nschwmtas04p.mx.bigpond.com with ESMTP id <20090830054223.KUPC2030.nschwmtas04p.mx.bigpond.com@nschwotgx01p.mx.bigpond.com>; Sun, 30 Aug 2009 05:42:23 +0000 Received: from bubble.grove.modra.org ([121.209.33.16]) by nschwotgx01p.mx.bigpond.com with ESMTP id <20090830054222.CHDI28976.nschwotgx01p.mx.bigpond.com@bubble.grove.modra.org>; Sun, 30 Aug 2009 05:42:22 +0000 Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 0D5DF170C880; Sun, 30 Aug 2009 15:12:22 +0930 (CST) Date: Sun, 30 Aug 2009 13:51:00 -0000 From: Alan Modra To: "H.J. Lu" Cc: binutils Subject: Re: PATCH: PR ld/10569: -z max-page-size may not work for linker scripts Message-ID: <20090830054221.GM19523@bubble.grove.modra.org> Mail-Followup-To: "H.J. Lu" , binutils References: <20090828000233.GA23692@lucon.org> <20090828031410.GC19523@bubble.grove.modra.org> <6dc9ffc80908272032p5b5a54a6h75caad74a27ffeda@mail.gmail.com> <6dc9ffc80908272055l3daa1368l1f84cfafcc07c2de@mail.gmail.com> <20090828055016.GE19523@bubble.grove.modra.org> <6dc9ffc80908280640q35b52922gda316d43127b7ab7@mail.gmail.com> <20090828143141.GK19523@bubble.grove.modra.org> <6dc9ffc80908280737q3b02c3e1ybfec435dd9307512@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6dc9ffc80908280737q3b02c3e1ybfec435dd9307512@mail.gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-RPD-ScanID: Class unknown; VirusThreatLevel unknown, RefID str=0001.0A150202.4A9A113F.004F,ss=1,fgs=0 X-SIH-MSG-ID: rhs0Edz5TAD0zmRy0WWwOwRzyFrsq3B48Z4QWs1mqRMGT0XduMfOII/9Y9IElp7l1C5MMxCBPGsiYLzmXY/YiA== 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: 2009-08/txt/msg00559.txt.bz2 On Fri, Aug 28, 2009 at 07:37:22AM -0700, H.J. Lu wrote: > Output target can be different from emulation target. Emulation target > may be ELF, which supports page sizes, while output target may not support > page sizes at all. We need to page sizes for both. Hmm, OK. If we are doing something like an "--oformat srec" link, then the bfd srec backend has no idea of page size, but the input files might be ELF and we might be using an ELF ld script which references MAXPAGESIZE. So the linker needs to know maxpagesize independently of the output. It just happens that the linker already has config.maxpagesize, so let's use that in ldexp.c. We will need to get config.maxpagesize from the bfd emulation target early in the link process, before we've parsed -z maxpagesize, and pass any changed value back before final link time. bfd/ PR ld/10569 * bfd.c (bfd_emul_get_maxpagesize): Don't abort. (bfd_emul_get_commonpagesize): Likewise. ld/ PR ld/10569 * ldexp.c (fold_name ): Return config.maxpagesize. (fold_name ): Similarly. * ldlang.c (output_target): Make global. * ldlang.h (output_target): Declare. * ldmain.c (main): Set config.maxpagesize from bfd_emul_get_maxpagesize. Similarly for config.commonpagesize. * ldemul.c (set_output_arch_default): Call bfd_emul_set_maxpagesize and bfd_emul_set_commonpagesize. * emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Don't call bfd_emul_set_maxpagesize or bfd_emul_set_commonpagesize here. Index: bfd/bfd.c =================================================================== RCS file: /cvs/src/src/bfd/bfd.c,v retrieving revision 1.109 diff -u -p -r1.109 bfd.c --- bfd/bfd.c 26 May 2009 14:12:02 -0000 1.109 +++ bfd/bfd.c 30 Aug 2009 05:17:57 -0000 @@ -1703,8 +1703,7 @@ DESCRIPTION emulation. RETURNS - Returns the maximum page size in bytes for ELF, abort - otherwise. + Returns the maximum page size in bytes for ELF, 0 otherwise. */ bfd_vma @@ -1717,7 +1716,6 @@ bfd_emul_get_maxpagesize (const char *em && target->flavour == bfd_target_elf_flavour) return xvec_get_elf_backend_data (target)->maxpagesize; - abort (); return 0; } @@ -1776,7 +1774,7 @@ DESCRIPTION emulation. RETURNS - Returns the common page size in bytes for ELF, abort otherwise. + Returns the common page size in bytes for ELF, 0 otherwise. */ bfd_vma @@ -1789,7 +1787,6 @@ bfd_emul_get_commonpagesize (const char && target->flavour == bfd_target_elf_flavour) return xvec_get_elf_backend_data (target)->commonpagesize; - abort (); return 0; } Index: ld/ldexp.c =================================================================== RCS file: /cvs/src/src/ld/ldexp.c,v retrieving revision 1.77 diff -u -p -r1.77 ldexp.c --- ld/ldexp.c 29 Aug 2009 22:11:01 -0000 1.77 +++ ld/ldexp.c 30 Aug 2009 05:19:24 -0000 @@ -673,9 +673,9 @@ fold_name (etree_type *tree) case CONSTANT: if (strcmp (tree->name.name, "MAXPAGESIZE") == 0) - new_abs (bfd_emul_get_maxpagesize (default_target)); + new_abs (config.maxpagesize); else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0) - new_abs (bfd_emul_get_commonpagesize (default_target)); + new_abs (config.commonpagesize); else einfo (_("%F%S: unknown constant `%s' referenced in expression\n"), tree->name.name); Index: ld/ldemul.c =================================================================== RCS file: /cvs/src/src/ld/ldemul.c,v retrieving revision 1.31 diff -u -p -r1.31 ldemul.c --- ld/ldemul.c 10 Aug 2009 07:50:56 -0000 1.31 +++ ld/ldemul.c 30 Aug 2009 05:19:23 -0000 @@ -228,6 +228,9 @@ set_output_arch_default (void) /* Set the output architecture and machine if possible. */ bfd_set_arch_mach (link_info.output_bfd, ldfile_output_architecture, ldfile_output_machine); + + bfd_emul_set_maxpagesize (output_target, config.maxpagesize); + bfd_emul_set_commonpagesize (output_target, config.commonpagesize); } void Index: ld/ldlang.c =================================================================== RCS file: /cvs/src/src/ld/ldlang.c,v retrieving revision 1.316 diff -u -p -r1.316 ldlang.c --- ld/ldlang.c 29 Aug 2009 22:11:01 -0000 1.316 +++ ld/ldlang.c 30 Aug 2009 05:19:27 -0000 @@ -52,6 +52,7 @@ static struct obstack map_obstack; #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free static const char *startup_file; +static const char *entry_symbol_default = "start"; static bfd_boolean placed_commons = FALSE; static bfd_boolean stripped_excluded_sections = FALSE; static lang_output_section_statement_type *default_common_section; @@ -59,7 +60,6 @@ static bfd_boolean map_option_f; static bfd_vma print_dot; static lang_input_statement_type *first_file; static const char *current_target; -static const char *output_target; static lang_statement_list_type statement_list; static struct bfd_hash_table lang_definedness_table; static lang_statement_list_type *stat_save[10]; @@ -86,13 +86,13 @@ static void lang_finalize_version_expr_h (struct bfd_elf_version_expr_head *); /* Exported variables. */ +const char *output_target; lang_output_section_statement_type *abs_output_section; lang_statement_list_type lang_output_section_statement; lang_statement_list_type *stat_ptr = &statement_list; lang_statement_list_type file_chain = { NULL, NULL }; lang_statement_list_type input_file_chain; struct bfd_sym_chain entry_symbol = { NULL, NULL }; -static const char *entry_symbol_default = "start"; const char *entry_section = ".text"; bfd_boolean entry_from_cmdline; bfd_boolean lang_has_input_file = FALSE; Index: ld/ldlang.h =================================================================== RCS file: /cvs/src/src/ld/ldlang.h,v retrieving revision 1.84 diff -u -p -r1.84 ldlang.h --- ld/ldlang.h 10 Aug 2009 07:50:56 -0000 1.84 +++ ld/ldlang.h 30 Aug 2009 05:19:27 -0000 @@ -445,6 +445,7 @@ struct orphan_save lang_output_section_statement_type **os_tail; }; +extern const char *output_target; extern lang_output_section_statement_type *abs_output_section; extern lang_statement_list_type lang_output_section_statement; extern bfd_boolean lang_has_input_file; Index: ld/ldmain.c =================================================================== RCS file: /cvs/src/src/ld/ldmain.c,v retrieving revision 1.136 diff -u -p -r1.136 ldmain.c --- ld/ldmain.c 27 May 2009 13:31:24 -0000 1.136 +++ ld/ldmain.c 30 Aug 2009 05:19:29 -0000 @@ -280,6 +280,8 @@ main (int argc, char **argv) emulation = get_emulation (argc, argv); ldemul_choose_mode (emulation); default_target = ldemul_choose_target (argc, argv); + config.maxpagesize = bfd_emul_get_maxpagesize (default_target); + config.commonpagesize = bfd_emul_get_commonpagesize (default_target); lang_init (); ldemul_before_parse (); lang_has_input_file = FALSE; Index: ld/emultempl/elf32.em =================================================================== RCS file: /cvs/src/src/ld/emultempl/elf32.em,v retrieving revision 1.199 diff -u -p -r1.199 elf32.em --- ld/emultempl/elf32.em 26 Aug 2009 13:08:07 -0000 1.199 +++ ld/emultempl/elf32.em 30 Aug 2009 05:19:30 -0000 @@ -2178,8 +2178,6 @@ fragment <