[PATCH V2] mkimage: fix segfault on MacOS arm64

mkimage segfaults due ASLR mechasim on MacOS arm64
It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64
This patch ased on the discussion https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af459...
Thanks to Ronny Kotzschmar and ptpt52 github user
Signed-off-by: Sergey V. Lobanov sergey@lobanov.in --- tools/imagetool.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/imagetool.h b/tools/imagetool.h index e229a34ffc..a0985d93d2 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -271,11 +271,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); \

CC: Jessica Clarke
On 17 Jan 2022, at 02:07, Sergey V. Lobanov sergey@lobanov.in wrote:
mkimage segfaults due ASLR mechasim on MacOS arm64
It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64
This patch ased on the discussion https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af459...
Thanks to Ronny Kotzschmar and ptpt52 github user
Signed-off-by: Sergey V. Lobanov sergey@lobanov.in
tools/imagetool.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/imagetool.h b/tools/imagetool.h index e229a34ffc..a0985d93d2 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -271,11 +271,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)); \
char *__cat(pstop_, name) = __cat(pstart_, name) + \ __cat(name, _len); \ __cat(__start_, name) = (void *)__cat(pstart_, name); \__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
-- 2.32.0 (Apple Git-132)

On Mon, Jan 17, 2022 at 02:07:13AM +0300, Sergey V. Lobanov wrote:
mkimage segfaults due ASLR mechasim on MacOS arm64
It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64
This patch ased on the discussion https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af459...
Thanks to Ronny Kotzschmar and ptpt52 github user
Signed-off-by: Sergey V. Lobanov sergey@lobanov.in
tools/imagetool.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/imagetool.h b/tools/imagetool.h index e229a34ffc..a0985d93d2 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -271,11 +271,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)); \
char *__cat(pstop_, name) = __cat(pstart_, name) + \ __cat(name, _len); \ __cat(__start_, name) = (void *)__cat(pstart_, name); \__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
This now seems sensible to me, thanks for fixing my mess.
Reviewed-by: Jessica Clarke jrtc27@jrtc27.com
(though you may want to clean up your commit message; "ased" is missing the leading b and you're still missing the verb "is", plus "mechasim" should be "mechanism" and it should be "due to the", not just "due")
Jess

Thank you, Jessica.
I have rebased on current master, added Reviewed-by tag, fixed grammar/typos and sent v3
On 25 Jan 2022, at 02:00, Jessica Clarke jrtc27@jrtc27.com wrote:
On Mon, Jan 17, 2022 at 02:07:13AM +0300, Sergey V. Lobanov wrote:
mkimage segfaults due ASLR mechasim on MacOS arm64
It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64
This patch ased on the discussion https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af459...
Thanks to Ronny Kotzschmar and ptpt52 github user
Signed-off-by: Sergey V. Lobanov sergey@lobanov.in
tools/imagetool.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/imagetool.h b/tools/imagetool.h index e229a34ffc..a0985d93d2 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -271,11 +271,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)); \
char *__cat(pstop_, name) = __cat(pstart_, name) + \ __cat(name, _len); \ __cat(__start_, name) = (void *)__cat(pstart_, name); \__cat(pstart_, name) += _dyld_get_image_vmaddr_slide(0);\
This now seems sensible to me, thanks for fixing my mess.
Reviewed-by: Jessica Clarke jrtc27@jrtc27.com
(though you may want to clean up your commit message; "ased" is missing the leading b and you're still missing the verb "is", plus "mechasim" should be "mechanism" and it should be "due to the", not just "due")
Jess
participants (2)
-
Jessica Clarke
-
Sergey V. Lobanov