Re: [PATCH] Check linker for --image-base support

Sudhakar Kuppusamy <[email protected]>
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>

> On 17 Nov 2025, at 12:32 AM, Nicholas Vinson <[email protected]> wrote:
> 
> In several scenarios, configure tests assume it's safe to use
> '-Wl,-Ttext,<address>', but starting with ld.lld-21, blindly using that
> flag may result in configure-test failures due to ld.lld failing to
> link. The failure is because ld.lld-21 no longer allows the specified
> address is less than the base address.
> 
> However, ld.lld-21+ and ld.bfd-2.44+ both provide support for the
> --image-base flag making it preferable over the older `-Ttext` flag.
> 
> Fixes: 67662
> Signed-off-by: Nicholas Vinson <[email protected]>

Reviewed-by: Sudhakar Kuppusamy <[email protected]>


Thanks,
Sudhakar  
> ---
> acinclude.m4 |  5 +++++
> configure.ac | 14 ++++++++++++--
> 2 files changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/acinclude.m4 b/acinclude.m4
> index fa7840f09..70c1912f8 100644
> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -79,6 +79,11 @@ AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
> [AC_MSG_CHECKING([whether ${TARGET_OBJCOPY} works for absolute addresses])
> AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
> [cat > conftest.c <<\EOF
> +asm (
> +    ".globl start, _start, __start\n"
> +    ".ifdef cmain; .set start = _start = __start = cmain\n.endif\n"
> +    ".ifdef _cmain; .set start = _start = __start = _cmain\n.endif\n"
> +);
> void cmain (void);
> void
> cmain (void)
> diff --git a/configure.ac b/configure.ac
> index 17937baf4..c9e2c5b8c 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1461,7 +1461,6 @@ elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_c
>   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img-ld.sc"
>   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
>   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img-ld.sc"
> -  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
>   TARGET_IMG_CFLAGS=
> else
>   TARGET_APPLE_LINKER=0
> @@ -1469,7 +1468,6 @@ else
>   TARGET_IMG_LDSCRIPT=
>   TARGET_IMG_LDFLAGS='-Wl,-N'
>   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
> -  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
>   TARGET_IMG_CFLAGS=
> fi
> 
> @@ -1795,6 +1793,18 @@ LIBS=""
> grub_ASM_USCORE
> grub_PROG_TARGET_CC
> if test "x$TARGET_APPLE_LINKER" != x1 ; then
> +AX_CHECK_LINK_FLAG([-Wl,--image-base,0x400000],
> +    [TARGET_IMG_BASE_LDOPT="-Wl,--image-base"],
> +    [TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"],
> +    [],
> +    [[
> +asm (".globl start; start:");
> +asm (".globl _start; _start:");
> +asm (".globl __start; __start:");
> +void __main (void);
> +void __main (void) {}
> +int main (void);
> +]])
> grub_PROG_OBJCOPY_ABSOLUTE
> fi
> grub_PROG_LD_BUILD_ID_NONE
> -- 
> 2.51.2
> 
> 
> _______________________________________________
> Grub-devel mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/grub-devel


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.