Skip to contentSkip to conversation

mkimage: fix segfault on MacOS arm64

PATCH In review Sergey V. Lobanov 2 participants 2 messages Jan 24, 2022 – Jan 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mkimage: fix segfault on MacOS arm64

mkimage segfaults due to the ASLR mechanism on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

This patch is based on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Jessica Clarke, Ronny Kotzschmar and ptpt52 github user

---
Changes since version 2:
- Rebased on current master
- Added Reviewed-by tag
- Fixed typos and grammatical errors

 tools/imagetool.h | 2 ++
 1 file changed, 2 insertions(+)
tools/imagetool.h +2 -0
index b7ac3a23d0..45eaada4b5 100644
@@ -272,11 +272,13 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams);
  *  b) we need a API call to get the respective section symbols */
 #if defined(__MACH__)
 #include <mach-o/getsect.h>
+#include <mach-o/dyld.h>
 
 #define INIT_SECTION(name)  do {					\
 		unsigned long name ## _len;				\
 		char *__cat(pstart_, name) = getsectdata("__DATA",	\
 			#name, &__cat(name, _len));			\
+		__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
 		char *__cat(pstop_, name) = __cat(pstart_, name) +	\
 			__cat(name, _len);				\
 		__cat(__start_, name) = (void *)__cat(pstart_, name);	\
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw
Quoted 5 lines · Sergey V. Lobanov

mkimage segfaults due to the ASLR mechanism on MacOS arm64

It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64

Quoted 7 lines

This patch is based on the discussion
https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0

Thanks to Jessica Clarke, Ronny Kotzschmar and ptpt52 github user

Applied to u-boot/master, thanks!

Signature · 1 line
Tom