u-boot/common
Paul Burton 703ec9ddf9 MIPS: Stop building position independent code
U-Boot has up until now built with -fpic for the MIPS architecture,
producing position independent code which uses indirection through a
global offset table, making relocation fairly straightforward as it
simply involves patching up GOT entries.

Using -fpic does however have some downsides. The biggest of these is
that generated code is bloated in various ways. For example, function
calls are indirected through the GOT & the t9 register:

  8f998064   lw     t9,-32668(gp)
  0320f809   jalr   t9

Without -fpic the call is simply:

  0f803f01   jal    be00fc04 <puts>

This is more compact & faster (due to the lack of the load & the
dependency the jump has on its result). It is also easier to read &
debug because the disassembly shows what function is being called,
rather than just an offset from gp which would then have to be looked up
in the ELF to discover the target function.

Another disadvantage of -fpic is that each function begins with a
sequence to calculate the value of the gp register, for example:

  3c1c0004   lui    gp,0x4
  279c3384   addiu  gp,gp,13188
  0399e021   addu   gp,gp,t9

Without using -fpic this sequence no longer appears at the start of each
function, reducing code size considerably.

This patch switches U-Boot from building with -fpic to building with
-fno-pic, in order to gain the benefits described above. The cost of
this is an extra step during the build process to extract relocation
data from the ELF & write it into a new .rel section in a compact
format, plus the added complexity of dealing with multiple types of
relocation rather than the single type that applied to the GOT. The
benefit is smaller, cleaner, more debuggable code. The relocate_code()
function is reimplemented in C to handle the new relocation scheme,
which also makes it easier to read & debug.

Taking maltael_defconfig as an example the size of u-boot.bin built
using the Codescape MIPS 2016.05-06 toolchain (gcc 4.9.2, binutils
2.24.90) shrinks from 254KiB to 224KiB.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: u-boot@lists.denx.de
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Tested-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
2017-07-25 20:44:00 +02:00
..
eeprom cmd: eeprom: add support for layout aware commands 2016-05-20 17:02:07 -04:00
init board_init.c: Always use memset() 2017-01-20 15:38:01 -05:00
spl mmc: add static to spl_mmc_get_device_index() 2017-07-19 19:13:59 +09:00
autoboot.c autoboot: move bootdelay >= 0 check to abortboot() 2016-07-01 17:42:56 -04:00
bedbug.c Consolidate bool type 2013-04-01 16:33:52 -04:00
board_f.c MIPS: Stop building position independent code 2017-07-25 20:44:00 +02:00
board_info.c generic-board: make show_board_info a weak function 2016-11-28 15:10:32 -05:00
board_r.c Allow displaying the U-Boot banner on a video display 2017-07-11 10:08:19 -06:00
boot_fit.c boot_fit: Create helper functions that can be used to select DTB out of FIT 2017-07-10 14:25:50 -04:00
bootm.c bootm: fix passing argc to standalone apps 2016-10-01 20:04:37 -04:00
bootm_os.c powerpc, 8xx: remove support for 8xx 2017-06-12 08:37:55 -04:00
bootretry.c Rename bootretry functions and remove #ifdefs 2014-05-29 17:49:00 -04:00
bootstage.c bootstage: Adjust to use const * where possible 2017-06-05 14:13:08 -04:00
bouncebuf.c Fix a few printf argument verification warnings 2014-09-15 13:32:55 -04:00
cli.c hush: complete renaming CONFIG_SYS_HUSH_PARSER to CONFIG_HUSH_PARSER 2016-06-24 17:24:34 -04:00
cli_hush.c hush: Add rudimentary support for PS1 and PS2 2016-02-08 10:10:37 -05:00
cli_readline.c common: cli_readline: Improve command line editing 2016-08-20 14:03:24 -04:00
cli_simple.c common: cli_simple: use strlcpy instead of strcpy 2016-01-13 21:05:26 -05:00
command.c Drop command-processing code when CONFIG_CMDLINE is disabled 2016-04-01 17:17:40 -04:00
common_fit.c spl: fit: Break out some functions into a common file 2017-07-10 14:24:39 -04:00
console.c sandbox: Drop special case console code for sandbox 2017-07-11 10:08:20 -06:00
cros_ec.c cros_ec: Remove unused cros_ec_board_init() function 2015-04-18 11:11:16 -06:00
ddr_spd.c Add more SPDX-License-Identifier tags 2016-01-19 08:31:21 -05:00
dfu.c common: dfu: ignore reset for spl-dfu 2017-05-12 08:37:09 -04:00
dlmalloc.c malloc: Turn on DEBUG when enabling unit tests 2017-06-05 14:13:11 -04:00
dlmalloc.src Consolidate bool type 2013-04-01 16:33:52 -04:00
edid.c edid: Use sizeof() in cea_is_hdmi_vsdb_present() 2017-06-12 08:38:06 -04:00
env_attr.c env: avoid possible NULL pointer access 2017-05-12 08:37:17 -04:00
env_callback.c common: env: initialize scalar variable 2016-01-04 12:25:35 -05:00
env_common.c env: Add generic redundant environment implementation 2017-07-22 15:36:17 -04:00
env_dataflash.c env: Add env_export() wrapper 2014-03-21 16:43:59 -04:00
env_eeprom.c env_eeprom invalidates gd->env_addr by setting it to an offset value 2016-04-11 12:44:37 -04:00
env_embedded.c tools/env: Correct include kconfig 2016-11-23 23:41:23 -08:00
env_ext4.c common: Fix support for environment file in EXT4 2016-06-24 17:24:35 -04:00
env_fat.c dm: block: Rename device number member dev to devnum 2016-03-14 15:34:50 -06:00
env_flags.c env: split fw_env.h in public and private parts 2017-04-12 13:28:28 -04:00
env_flash.c env_flash.c: Drop unused variables 2014-04-17 17:44:36 -04:00
env_mmc.c env: Switch env_nand, env_mmc and env_ubi to env_import_redund 2017-07-22 15:36:17 -04:00
env_nand.c env: Switch env_nand, env_mmc and env_ubi to env_import_redund 2017-07-22 15:36:17 -04:00
env_nowhere.c Coding Style cleanup: remove trailing white space 2013-10-14 16:06:53 -04:00
env_nvram.c env: Add env_export() wrapper 2014-03-21 16:43:59 -04:00
env_onenand.c env: Add env_export() wrapper 2014-03-21 16:43:59 -04:00
env_remote.c Coding Style cleanup: remove trailing white space 2013-10-14 16:06:53 -04:00
env_sata.c common: env: support sata device 2016-04-18 12:29:14 -04:00
env_sf.c dm: Use dm.h header when driver mode is used 2017-06-01 06:57:52 -06:00
env_ubi.c env: Switch env_nand, env_mmc and env_ubi to env_import_redund 2017-07-22 15:36:17 -04:00
exports.c board/ls2085rdb: Export functions for standalone AQ FW load apps 2015-07-20 11:44:37 -07:00
fb_mmc.c fastboot: Add support for flashing zImage 2017-06-03 19:08:31 +02:00
fb_nand.c common: use get_nand_dev_by_index() 2017-07-11 22:41:46 -04:00
fdt_support.c powerpc: remove 4xx support 2017-07-03 17:35:28 -04:00
flash.c flash: compile common/flash.c iif CONFIG_MTD_NO_FLASH is enabled 2017-02-12 14:30:31 -05:00
hash.c Kconfig: Finish migration of hashing commands 2017-05-31 19:38:14 -04:00
hwconfig.c Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
image-android.c image: Update include/android_image.h 2017-05-11 22:03:37 -04:00
image-fdt.c fdt: Move fdt_fixup_ethernet to a common place 2017-05-01 09:11:59 -04:00
image-fit.c splash: add support for loading splash from a FIT image 2017-01-13 17:40:38 +01:00
image-sig.c image: Combine image_sig_algo with image_sign_info 2016-11-21 14:07:31 -05:00
image-sparse.c fastboot: sparse: improve CHUNK_TYPE_FILL write performance 2016-06-27 16:37:39 -04:00
image.c common/image.c: Use correct suffixes for binary sizes 2017-01-20 15:37:59 -05:00
iomux.c console: Don't enable CONFIG-CONSOLE_MUX, etc. in SPL 2017-02-06 11:38:46 +08:00
iotrace.c common: Make sure arch-specific map_sysmem() is defined 2015-04-18 11:11:09 -06:00
kallsyms.c Add support for Linux-like kallsysms 2009-06-12 20:45:48 +02:00
Kconfig sandbox: Enable more console options 2017-07-11 10:08:20 -06:00
kgdb.c Fix spelling of "occurred". 2016-05-02 18:37:09 -04:00
kgdb_stubs.c Use correct spelling of "U-Boot" 2016-02-06 12:00:59 +01:00
lcd.c powerpc, 8xx: remove support for 8xx 2017-06-12 08:37:55 -04:00
lcd_console.c common/lcd_console: introduce display/framebuffer rotation 2015-04-18 17:40:37 +02:00
lcd_console_rotation.c common/lcd_console: introduce display/framebuffer rotation 2015-04-18 17:40:37 +02:00
lcd_simplefb.c dm: video: Add driver-model support to lcd_simplefb 2017-05-09 20:20:41 -04:00
lynxkdi.c powerpc: remove 4xx support 2017-07-03 17:35:28 -04:00
main.c Drop use of CONFIG_SYS_GENERIC_BOARD in U-Boot 2016-05-27 15:39:54 -04:00
Makefile scsi: Move drivers into new drivers/scsi directory 2017-07-11 10:08:19 -06:00
malloc_simple.c malloc_simple: Add debug statements to memalign_simple 2017-01-28 14:04:34 -05:00
memsize.c Revert "common/memsize.c: Simplify RAM size detection" 2016-02-10 08:34:42 -05:00
menu.c Fix typo choosen in comments and printf logs 2016-03-27 09:12:23 -04:00
miiphyutil.c common: miiphyutil: Add helper function for mdio bus name 2016-12-20 07:40:04 +01:00
s_record.c Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
splash.c splash: Introduce default_splash_locations 2016-07-26 08:47:37 +02:00
splash_source.c common: use get_nand_dev_by_index() 2017-07-11 22:41:46 -04:00
stdio.c i2c: Finish dropping use of CONFIG_I2C_HARD 2017-05-15 06:18:30 +02:00
system_map.c Add support for Linux-like kallsysms 2009-06-12 20:45:48 +02:00
update.c flash: complete CONFIG_SYS_NO_FLASH move with renaming 2017-02-12 14:30:25 -05:00
usb.c powerpc: remove 4xx support 2017-07-03 17:35:28 -04:00
usb_hub.c powerpc: remove 4xx support 2017-07-03 17:35:28 -04:00
usb_kbd.c console: Don't enable CONFIG-CONSOLE_MUX, etc. in SPL 2017-02-06 11:38:46 +08:00
usb_storage.c dm: scsi: Drop the ccb typedef 2017-07-11 10:08:19 -06:00
xyzModem.c common/xyzModem.c: Do not use hard-coded address for debug buffer 2017-04-08 09:26:55 -04:00