[rulkc] [PATCH 1/1] package/mtd: build with -fPIC when shared libraries are enabled

Konstantin Menyaev viper at landau.one
Sun Aug 9 11:26:22 MSK 2026


On 8/2/26 01:29, viper at landau.one wrote:
> From: Konstantin Menyaev <viper at landau.one>
> 
> Historically, mtd-utils only provided static libraries, so they are
> built without -fPIC.
> 
> This becomes an issue for configs with shared libraries,
> where apps may need to link libmtd.a or libubi.a
> into shared objects, resulting in relocation errors.
> 
> Build the MTD package with -fPIC when shared libraries are enabled,
> while keeping static-only builds unchanged.
> 
> Signed-off-by: Konstantin Menyaev <viper at landau.one>
> ---
>   package/mtd/mtd.mk | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/package/mtd/mtd.mk b/package/mtd/mtd.mk
> index 2a625fccce..d67770d5ba 100644
> --- a/package/mtd/mtd.mk
> +++ b/package/mtd/mtd.mk
> @@ -14,8 +14,13 @@ MTD_CPE_ID_PRODUCT = mtd-utils
>   MTD_INSTALL_STAGING = YES
>   MTD_DEPENDENCIES = host-pkgconf
>   
> +MTD_CFLAGS = $(TARGET_CFLAGS)
>   MTD_LDFLAGS = $(TARGET_LDFLAGS)
>   
> +ifeq ($(BR2_SHARED_LIBS)$(BR2_STATIC_SHARED_LIBS),y)
> +MTD_CFLAGS += -fPIC
> +endif
> +
>   ifeq ($(BR2_PACKAGE_LIBEXECINFO),y)
>   MTD_DEPENDENCIES += libexecinfo
>   MTD_LDFLAGS += -lexecinfo
> @@ -35,7 +40,7 @@ else
>   MTD_CONF_OPTS += --without-zlib
>   endif
>   
> -MTD_CONF_ENV += LDFLAGS="$(MTD_LDFLAGS)"
> +MTD_CONF_ENV += CFLAGS="$(MTD_CFLAGS)" LDFLAGS="$(MTD_LDFLAGS)"
>   
>   ifeq ($(BR2_PACKAGE_MTD_JFFS_UTILS),y)
>   MTD_CONF_OPTS += --with-jffs

kindly ping



More information about the rulkc mailing list