0

I built up a tool chain with gcc-6.2 with all the latest components.

CC      = arm-none-eabi-gcc
AS      = arm-none-eabi-as
LD      = arm-none-eabi-ld

My Makefile flags are:

CFLAGS = -std=c11 -Wall -Werror -Wfatal-errors -Wstrict-prototypes -Wundef -gdwarf-2 -O2 -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian

LDFLAGS = -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

I am linking by having via the compiler. CFLAGS at the front and LDFLAGS at the rear:

Linking: ugui3.elf
arm-none-eabi-gcc -std=c11 -Wall -Werror -Wfatal-errors -Wstrict prototypes -Wundef -gdwarf-2 -O2 -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian stm32746g_discovery.o stm32746g_discovery_lcd.o stm32746g_discovery_sdram.o stm32746g_discovery_ts.o system_stm32f7xx.o stm32f7xx_hal.o stm32f7xx_hal_cortex.o stm32f7xx_hal_dma.o stm32f7xx_hal_dma2d.o stm32f7xx_hal_dma_ex.o stm32f7xx_hal_gpio.o stm32f7xx_hal_i2c.o stm32f7xx_hal_i2c_ex.o stm32f7xx_hal_ltdc.o stm32f7xx_hal_pwr.o stm32f7xx_hal_pwr_ex.o stm32f7xx_hal_rcc.o stm32f7xx_hal_rcc_ex.o stm32f7xx_hal_sdram.o stm32f7xx_hal_uart.o stm32f7xx_ll_fmc.o stm32f7xx_hal_msp.o stm32f7xx_it.o main.o ugui.o ltdc.o sdram.o ft5336.o small_printf.o startup_stm32f746xx.o --output ugui3.elf -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

I can reduce what is in CFLAGS to just: CFLAGS = -mthumb -mthumb-interwork

Linking: ugui3.elf
arm-none-eabi-gcc -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian stm32746g_discovery.o stm32746g_discovery_lcd.o stm32746g_discovery_sdram.o stm32746g_discovery_ts.o system_stm32f7xx.o stm32f7xx_hal.o stm32f7xx_hal_cortex.o stm32f7xx_hal_dma.o stm32f7xx_hal_dma2d.o stm32f7xx_hal_dma_ex.o stm32f7xx_hal_gpio.o stm32f7xx_hal_i2c.o stm32f7xx_hal_i2c_ex.o stm32f7xx_hal_ltdc.o stm32f7xx_hal_pwr.o stm32f7xx_hal_pwr_ex.o stm32f7xx_hal_rcc.o stm32f7xx_hal_rcc_ex.o stm32f7xx_hal_sdram.o stm32f7xx_hal_uart.o stm32f7xx_ll_fmc.o stm32f7xx_hal_msp.o stm32f7xx_it.o main.o ugui.o ltdc.o sdram.o ft5336.o small_printf.o startup_stm32f746xx.o --output ugui3.elf -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

My questions:

  1. Is invoking the linker (shown above) via the compiler preferred?

  2. Is the first method better than the second method? Is there a better way?

rsun
  • 63
  • 1
  • 7

1 Answers1

0

I migrated to a few other projects and continued looking into this.

A:
arm-none-eabi-gcc -mthumb < .o files > --output image.elf -T./lpc1768.ld -nostartfiles -Wl,-Map=image.map,--cref

B:
arm-none-eabi-gcc < .o files > --output image.elf -T./lpc1768.ld -nostartfiles -Wl,-Map=image.map,--cref -L /usr/local/arm-none-eabi/lib/thumb

A and B both work. Method A with "-mthumb" assumes you want to link with the thumb version of libc.a. Method B specifies the thumb version as -L /usr/local/arm-none-eabi/lib/thumb

On yet another project I can get away with a minimal line on the link, no -mthumb flag and no library path.

C:
arm-none-eabi-gcc < .o files > --output image.elf -T./lpc2132.ld -nostartfiles -Wl,-Map=image.map,--cref

Method C works on a lpc2132(arm7tdmi-s) project. But method C does not work on the lpc1768(Cortex-m3) project (A & B). They have almost identical .ld files and start files.

The reason that method C does not work (no explicit library or path) is that the ARM libraries are linked by default. Since the lpc1768 is a thumb-only processor this is not good. A "-mthumb" or a "-L path to thumb library" is necessary.

rsun
  • 63
  • 1
  • 7