From patchwork Mon Jan 7 19:59:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 210083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0567B2C0086 for ; Tue, 8 Jan 2013 06:59:29 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1358193570; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=FAPOp+E 2gnldMg3Vb2gwvQaYgnk=; b=upt74eFvgJlnNGGm59PRdTKgLk8GSmtNZKabGq1 NaIfqBx1k4HUXVMcu0mu+B7h9p+d6BdUndpSuxj9Pm64sNzBWm/DgnD+zp9WqQIF 3uP1Kb1phLtOLfzuphwBVNCNMOiRltApITAhPgNzHbiNXKo82CJ9NoSO1+ZfU3ip GlpU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:X-RZG-AUTH:X-RZG-CLASS-ID:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=RiVtIifECPQAySUBlPukd/nPROBrF63W4AlMRfNk9lM9V/dgWijqNj8gF8+oXs x05NbvLrW3oarUdEaLWpfqSJHXpz7vwDTcemgu63RunwNAcXqKKa4uyClyBtMW/i 0tdkrfbgiaZfkYPAWkfblZCSYRu0RASJ/Be6PBJ1ZUxW8=; Received: (qmail 19987 invoked by alias); 7 Jan 2013 19:59:23 -0000 Received: (qmail 19979 invoked by uid 22791); 7 Jan 2013 19:59:22 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mo-p00-ob.rzone.de (HELO mo-p00-ob.rzone.de) (81.169.146.161) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Jan 2013 19:59:09 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT2k715jHQaJercGObUOFkj18odoYNahU4Q== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.22] (business-188-111-022-002.static.arcor-ip.net [188.111.22.2]) by smtp.strato.de (joses mo46) (RZmta 31.11 AUTH) with ESMTPA id D0645ep07ID2IO ; Mon, 7 Jan 2013 20:59:04 +0100 (CET) Message-ID: <50EB2907.7050004@gjlay.de> Date: Mon, 07 Jan 2013 20:59:03 +0100 From: Georg-Johann Lay User-Agent: Thunderbird 2.0.0.24 (X11/20100302) MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org CC: Denis Chertykov , Eric Weddington Subject: [Patch, avr] Add predicate symbols for the linker script to bump sections containing addr-space data X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This is a tentative patch that adds symbols that can be used as predicates in the linker script. Background is binutils PR14406: Data in address space __flash1 must be located in such a way that the high byte (hh8) of the address is 0x1. This is needed because avr-gcc sets RAMPZ to 0x1 before reading data from __flash1. The input section for __flash1 is .progmem1.data Similar for other __flash, n = 2..5 The problems to be solved are: 1) .progmem.data must be located in [0x0000, 0xffff]. 2) If there is too much data in .progmem.data the linker should complain. 3) Moving the location counter to 0x0000 is only needed if .progmem is non-empty. 4) We must be careful not to move to pointer backwards. 5) User-level build-scripts and Makefiles should be the same if the user does not use the new features like __flash. Even if __flash is used, it's appreciated if everything works out of the box and without changing calls of objcopy, for example. 6) If .text extends to, say, 0x20010, it's still fine if .progmem2.data starts at 0x20011. There is no need to throw an error because text overlaps 0x20000...0x2ffff. The very problem is that the linker script language is too limited. Neither does it support memory holes, nor can a section float around others, and not even detecting if a section does not contain any data works as promised by binutils, cf. [1]. The patch addresses the latter problem: It defines symbols that can be used like predicates by the linker script like so, cf. [2]: .text : { ... . = MAX (DEFINED(__need_.progmem1.data) ? 1 << 16 : 0, ABSOLUTE(.)) ; __progmem1_start = . ; *(.progmem1) *(.progmem1.*) __progmem1_end = . ; ... } > text There was some discussion in [3] about how PR14406 could be approached and there were basically two proposals: - One from Erik that does not solve 3), 6) or 5) i.e. requires a change in the user Makefiles like -j .hightext instead of -j .text etc. .text is after .progmem - One from me with the predicate-like-symbols kludge that needs a GCC change and has less informative error messages than Erik's approach in the case anything overflows. .text is before .progmem Maybe everything can be solved much easier and I am lacking the respective binutils knowledge... Thoughts? Johann [1] http://sourceware.org/ml/binutils/2012-12/msg00151.html [2] http://lists.gnu.org/archive/html/avr-gcc-list/2012-12/msg00046.html [3] http://lists.gnu.org/archive/html/avr-gcc-list/2012-12/msg00029.html gcc/ * config/avr/avr.c (avr_need_addrspace_p): New static variable. (avr_asm_named_section): Record avr_need_addrspace_p. (avr_asm_select_section): Ditto. (avr_asm_function_rodata_section): Ditto. (avr_file_end): Reference __need_.progmem.data according to avr_need_addrspace_p[N]. libgcc/ * config/avr/t-avr (LIB1ASMFUNCS): Add: _progmem1, _progmem2, _progmem3, _progmem4, _progmem5. * config/avr/lib1funcs.S (__need_.progmem1.data) (__need_.progmem2.data, __need_.progmem3.data) (__need_.progmem4.data, __need_.progmem5.data): Define symbols. Index: gcc/config/avr/avr.c =================================================================== --- gcc/config/avr/avr.c (revision 194991) +++ gcc/config/avr/avr.c (working copy) @@ -205,6 +205,10 @@ bool avr_have_dimode = true; bool avr_need_clear_bss_p = false; bool avr_need_copy_data_p = false; +/* Track need for the non-generic address spaces, similar to + avr_need_copy_data_p. */ +static bool avr_need_addrspace_p[ADDR_SPACE_COUNT]; + /* Custom function to count number of set bits. */ @@ -8148,6 +8152,9 @@ avr_asm_function_rodata_section (tree de flags = frodata->common.flags; } + /* Just for the record... */ + avr_need_addrspace_p[ADDR_SPACE_FLASH] = true; + if (frodata != readonly_data_section && flags & SECTION_NAMED) { @@ -8195,6 +8202,8 @@ avr_asm_named_section (const char *name, const char *old_prefix = ".rodata"; const char *new_prefix = avr_addrspace[as].section_name; + avr_need_addrspace_p[as] = true; + if (STR_PREFIX_P (name, old_prefix)) { const char *sname = ACONCAT ((new_prefix, @@ -8313,6 +8322,8 @@ avr_asm_select_section (tree decl, int r if (ADDR_SPACE_GENERIC_P (as)) as = ADDR_SPACE_FLASH; + avr_need_addrspace_p[as] = true; + if (sect->common.flags & SECTION_NAMED) { const char * name = sect->named.name; @@ -8393,6 +8404,27 @@ avr_file_end (void) if (avr_need_clear_bss_p) fputs (".global __do_clear_bss\n", asm_out_file); + + for (size_t n = 0; n < ADDR_SPACE_COUNT; n++) + { + addr_space_t as = (addr_space_t) n; + + if (avr_need_addrspace_p[as] + /* We only need the __need_ symbols in the linker script for + the paged sections that move the location counter forward. + For example, bumping the location counter to 0x10000 for + __flash1 / .progmem1.data is only needed if that input section + is non-empty. The linker script language is not generic enough + to express this. Thus, we trigger the definition of a symbol + that can be used as predicate via DEFINED(symbol). */ + && !ADDR_SPACE_GENERIC_P (as) + && ADDR_SPACE_FLASH != as + && ADDR_SPACE_MEMX != as) + { + fprintf (asm_out_file, ".global __need_%s\n", + avr_addrspace[as].section_name); + } + } } /* Choose the order in which to allocate hard registers for Index: libgcc/config/avr/lib1funcs.S =================================================================== --- libgcc/config/avr/lib1funcs.S (revision 194964) +++ libgcc/config/avr/lib1funcs.S (working copy) @@ -2935,4 +2935,37 @@ ENDF __fmul #undef C0 #undef C1 +;; Marker Symbols to be used in the Linker Script. +;; GCC will acquire them if any data is put into .progmem.data + +#if defined L_progmem1 +.section .progmem1.data, "a", @progbits +.global __need_.progmem1.data +__need_.progmem1.data: +#endif /* L_progmem1 */ + +#if defined L_progmem2 +.section .progmem2.data, "a", @progbits +.global __need_.progmem2.data +__need_.progmem2.data: +#endif /* L_progmem2 */ + +#if defined L_progmem3 +.section .progmem3.data, "a", @progbits +.global __need_.progmem3.data +__need_.progmem3.data: +#endif /* L_progmem3 */ + +#if defined L_progmem4 +.section .progmem4.data, "a", @progbits +.global __need_.progmem4.data +__need_.progmem4.data: +#endif /* L_progmem4 */ + +#if defined L_progmem5 +.section .progmem5.data, "a", @progbits +.global __need_.progmem5.data +__need_.progmem5.data: +#endif /* L_progmem5 */ + #include "lib1funcs-fixed.S" Index: libgcc/config/avr/t-avr =================================================================== --- libgcc/config/avr/t-avr (revision 194964) +++ libgcc/config/avr/t-avr (working copy) @@ -77,7 +77,9 @@ LIB1ASMFUNCS += \ _ssneg_2 _ssneg_4 _ssneg_8 \ _ssabs_2 _ssabs_4 _ssabs_8 \ _ssadd_8 _sssub_8 \ - _usadd_8 _ussub_8 + _usadd_8 _ussub_8 \ + \ + _progmem1 _progmem2 _progmem3 _progmem4 _progmem5 LIB2FUNCS_EXCLUDE = \ _moddi3 _umoddi3 \