Skip to content

Commit cbe55ac

Browse files
committed
Fix embedded images built with the clang compiler
1 parent 2aef0ed commit cbe55ac

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

arch.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,14 +1288,17 @@ ifeq ($(USE_CLANG),1)
12881288
CLANG_NEWLIB_INCLUDE?=$(abspath $(dir $(CLANG_LIBC_A))/../include)
12891289

12901290
CC=$(CLANG_DRIVER)
1291-
LD=$(CLANG_DRIVER)
1291+
# Keep clang for compilation, but use the GNU linker driver so linker-script
1292+
# LMAs for RAM sections are preserved and objcopy does not emit sparse images.
1293+
LD=$(CLANG_GCC_NAME)
12921294
AS=$(CLANG_DRIVER)
12931295
AR=$(CROSS_COMPILE)ar
12941296
OBJCOPY?=$(CROSS_COMPILE)objcopy
12951297
SIZE=$(CROSS_COMPILE)size
12961298

12971299
CFLAGS+=-isystem $(CLANG_NEWLIB_INCLUDE)
12981300
CFLAGS+=-DWOLFSSL_NO_ATOMIC -DWOLFSSL_NO_ATOMICS
1301+
CFLAGS+=-Wno-unknown-attributes -Wno-error=unknown-attributes
12991302
LDFLAGS+=-nostdlib
13001303
endif
13011304

test-app/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map -nostartfiles
102102

103103
# Setup default objcopy flags
104104
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)
105+
OBJCOPY_IMAGE_FLAGS:=
106+
107+
ifeq ($(USE_CLANG),1)
108+
# Clang-built ARM ELFs can keep RAM sections as loadable segments, and raw
109+
# objcopy output then expands the flash-to-RAM gap into a huge sparse image.
110+
# The app image only needs the flash-backed output sections.
111+
OBJCOPY_IMAGE_FLAGS+=-j .text -j .edidx
112+
endif
105113

106114
ifeq ($(DEBUG_UART),1)
107115
CFLAGS+=-DDEBUG_UART
@@ -913,15 +921,15 @@ delta-extra-data:LDFLAGS=-Wl,-Map=image.map
913921

914922
image.bin: image.elf
915923
@echo "\t[BIN] $@"
916-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@
924+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O binary $^ $@
917925

918926
image.hex: image.elf
919927
@echo "\t[HEX] $@"
920-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O ihex $^ $@
928+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O ihex $^ $@
921929

922930
image.srec: image.elf
923931
@echo "\t[SREC] $@"
924-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O srec $^ $@
932+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O srec $^ $@
925933

926934
APP_OBJS := $(patsubst $(WOLFBOOT_LIB_WOLFSSL)/%, \
927935
$(WOLFSSL_LOCAL_OBJDIR)/%, $(APP_OBJS))

0 commit comments

Comments
 (0)