Skip to content

Commit cb69bb9

Browse files
committed
Fix embedded images built with the clang compiler
1 parent 5222385 commit cb69bb9

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
@@ -1282,14 +1282,17 @@ ifeq ($(USE_CLANG),1)
12821282
CLANG_NEWLIB_INCLUDE?=$(abspath $(dir $(CLANG_LIBC_A))/../include)
12831283

12841284
CC=$(CLANG_DRIVER)
1285-
LD=$(CLANG_DRIVER)
1285+
# Keep clang for compilation, but use the GNU linker driver so linker-script
1286+
# LMAs for RAM sections are preserved and objcopy does not emit sparse images.
1287+
LD=$(CLANG_GCC_NAME)
12861288
AS=$(CLANG_DRIVER)
12871289
AR=$(CROSS_COMPILE)ar
12881290
OBJCOPY?=$(CROSS_COMPILE)objcopy
12891291
SIZE=$(CROSS_COMPILE)size
12901292

12911293
CFLAGS+=-isystem $(CLANG_NEWLIB_INCLUDE)
12921294
CFLAGS+=-DWOLFSSL_NO_ATOMIC -DWOLFSSL_NO_ATOMICS
1295+
CFLAGS+=-Wno-unknown-attributes -Wno-error=unknown-attributes
12931296
LDFLAGS+=-nostdlib
12941297
endif
12951298

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
@@ -899,15 +907,15 @@ delta-extra-data:LDFLAGS=-Wl,-Map=image.map
899907

900908
image.bin: image.elf
901909
@echo "\t[BIN] $@"
902-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@
910+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O binary $^ $@
903911

904912
image.hex: image.elf
905913
@echo "\t[HEX] $@"
906-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O ihex $^ $@
914+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O ihex $^ $@
907915

908916
image.srec: image.elf
909917
@echo "\t[SREC] $@"
910-
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O srec $^ $@
918+
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) $(OBJCOPY_IMAGE_FLAGS) -O srec $^ $@
911919

912920
APP_OBJS := $(patsubst $(WOLFBOOT_LIB_WOLFSSL)/%, \
913921
$(WOLFSSL_LOCAL_OBJDIR)/%, $(APP_OBJS))

0 commit comments

Comments
 (0)