Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: "J. Neuschäfer" <j.neuschaefer@gmx.net>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH v2 1/2] Config.in: ban textrels on musl toolchains
Date: Sat, 1 Jun 2024 22:59:53 +0200	[thread overview]
Message-ID: <ZluLyQ7JHFYedvcv@landeda> (raw)
In-Reply-To: <20240529-ztext-v2-1-82985032f169@gmx.net>

On 2024-05-29 20:22 +0200, J. Neuschäfer via buildroot spake thusly:
> musl-libc doesn't support TEXTRELs[1] and programs with TEXTRELs will
> crash on start-up under musl.
> 
> This patch forbids the use of TEXTRELs on musl, but adds an option to
> either forbid them on other libcs as well, or allow them on musl.

In your v1, Thomas suggested that textrels be simply always disabled for
musl, because there is no way they can work. Allowing people to enable
them on musl will only make things reak at runtime, rather than at build
time.

I'm on the same page as Thomas here: if textrels are unsupported on
musl, then let's not allow them at all.

> [1]: https://www.openwall.com/lists/musl/2020/09/25/4
> 
> Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
> ---
[--SNIP--]
> diff --git a/Config.in b/Config.in
> index b5a94325c4..92e89ed32d 100644
> --- a/Config.in
> +++ b/Config.in
> @@ -910,6 +910,20 @@ endchoice
>  comment "RELocation Read Only (RELRO) needs shared libraries"
>  	depends on !BR2_SHARED_LIBS
> 
> +config BR2_LINK_ZTEXT
> +	bool "Disallow text section relocations (TEXTRELs)"

We prefer positive logic:

    config BR2_LINK_ZTEXT
        bool "Allow text section relocations (TEXTRELs)"
        default y  # Legacy
        depends on !BR2_TOOLCHAIN_USES_MUSL
        depends on !BR2_STATIC_LIBS

and in the .mk:

    ifeq ($(BR2_LINK_ZTEXT),)
    TARGET_LDFLAGS += -z text
    endif

(Note the 'default y': textrels were previously always allowed, so we
want to keep that behaviour by default)

Regards,
Yann E. MORIN.

> +	default BR2_TOOLCHAIN_USES_MUSL
> +	depends on !BR2_STATIC_LIBS
> +	help
> +	  Pass "-z text" to the linker to detect TEXTRELs and throw an
> +	  error if they occur.
> +
> +	  This is recommended when building a system with musl-libc,
> +	  because TEXTRELs are not supported on musl-libc's dynamic
> +	  loader and will result in a run-time crash:
> +
> +	    https://www.openwall.com/lists/musl/2020/09/25/4
> +
>  config BR2_FORTIFY_SOURCE_ARCH_SUPPORTS
>  	bool
>  	default y
> diff --git a/package/Makefile.in b/package/Makefile.in
> index f415e55f84..68efd39dba 100644
> --- a/package/Makefile.in
> +++ b/package/Makefile.in
> @@ -149,6 +149,10 @@ endif
> 
>  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
> 
> +ifeq ($(BR2_LINK_ZTEXT),y)
> +TARGET_LDFLAGS += -z text
> +endif
> +
>  # By design, _FORTIFY_SOURCE requires gcc optimization to be enabled.
>  # Therefore, we need to pass _FORTIFY_SOURCE and the optimization level
>  # through the same mechanism, i.e currently through CFLAGS. Passing
> 
> --
> 2.43.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2024-06-01 21:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 18:22 [Buildroot] [PATCH v2 0/2] Add option to ban textrels J. Neuschäfer via buildroot
2024-05-29 18:22 ` [Buildroot] [PATCH v2 1/2] Config.in: ban textrels on musl toolchains J. Neuschäfer via buildroot
2024-06-01 20:59   ` Yann E. MORIN [this message]
2024-06-09 12:54     ` J. Neuschäfer via buildroot
2024-05-29 18:22 ` [Buildroot] [PATCH v2 2/2] micropython: Add patch to avoid textrel on arm/thumb J. Neuschäfer via buildroot
2024-06-01 20:51   ` Yann E. MORIN
2024-06-08 17:01   ` Peter Korsgaard
2024-06-09  4:12     ` Baruch Siach via buildroot
2024-06-09  8:33       ` Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZluLyQ7JHFYedvcv@landeda \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@buildroot.org \
    --cc=j.neuschaefer@gmx.net \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox