From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83315 invoked by alias); 7 Jul 2015 17:45:13 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 83302 invoked by uid 89); 7 Jul 2015 17:45:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: plane.gmane.org Received: from plane.gmane.org (HELO plane.gmane.org) (80.91.229.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 07 Jul 2015 17:45:12 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZCWvc-00088Q-MT for gcc-help@gcc.gnu.org; Tue, 07 Jul 2015 19:45:08 +0200 Received: from c-73-162-230-66.hsd1.ca.comcast.net ([73.162.230.66]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Jul 2015 19:45:03 +0200 Received: from ccollins476ad by c-73-162-230-66.hsd1.ca.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Jul 2015 19:45:03 +0200 To: gcc-help@gcc.gnu.org From: Christopher Collins Subject: Position-independent code; fixed-address data and bss Date: Tue, 07 Jul 2015 17:45:00 -0000 Message-ID: User-Agent: slrn/1.0.1 (Linux) X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg00027.txt.bz2 MCU: STM32F4 (ARM Cortex M4) Build environment: arm-none-eabi-gcc 4.8.4 20140725 My goal is to build an image that can be run from any properly-aligned offset in internal flash (i.e., position-independent). I found the following set of gcc flags that achieves this goal: # Generate position independent code. -fPIC # Access bss via the GOT. -mno-pic-data-is-text-relative # GOT is not PC-relative; store GOT location in a register. -msingle-pic-base # Store GOT location in r9. -mpic-register=r9 This works, but now I am wondering if there is a way to reduce the size of the resulting binary. In particular, the above flags cause all global variables to be accessed via the global offset table (GOT). However, I don't need this extra indirection, because the data and bss sections will always be at fixed offsets in SRAM. The only part of the image that needs to be position independent is the code itself. Ideally, I would like to gcc to treat all accesses to global variables as though it weren't generating position-independent code. Any ideas? All input is greatly appreciated. Thanks, Chris