diff mbox series

[uclibc-ng-devel] Add extra `-shared` to link.so command.

Message ID 20240211062954.6200-1-dm.chestnykh@gmail.com
State Accepted
Headers show
Series [uclibc-ng-devel] Add extra `-shared` to link.so command. | expand

Commit Message

Dmitry Chestnykh Feb. 11, 2024, 6:29 a.m. UTC
While compiling OpenADK I discovered that
there may be a case where UCLIBC_EXTRA_LDFLAGS
contains `-fpie -pie`. Linker ignores `-shared`
if `-pie` flag is passed after and produces
an executable binary instead of shared object.
This leads to linking failure because `ld-uClibc.so.1`
becomes executable instead of shared object.
`ld-uClibc.so.1` is used as one of the inputs
when linking of libc.so.1 and linking proccess fails.
To prevent this issue we need to pass extra `-shared` flag
in `link.so` target command after all other flags to overwrite
`-pie` effect.

Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
---
 Makerules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dmitry Chestnykh Feb. 11, 2024, 6:31 a.m. UTC | #1
My OpenADK config in attachment

вс, 11 февр. 2024 г. в 09:29, Dmitry Chestnykh <dm.chestnykh@gmail.com>:

> While compiling OpenADK I discovered that
> there may be a case where UCLIBC_EXTRA_LDFLAGS
> contains `-fpie -pie`. Linker ignores `-shared`
> if `-pie` flag is passed after and produces
> an executable binary instead of shared object.
> This leads to linking failure because `ld-uClibc.so.1`
> becomes executable instead of shared object.
> `ld-uClibc.so.1` is used as one of the inputs
> when linking of libc.so.1 and linking proccess fails.
> To prevent this issue we need to pass extra `-shared` flag
> in `link.so` target command after all other flags to overwrite
> `-pie` effect.
>
> Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
> ---
>  Makerules | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Makerules b/Makerules
> index 1a7443c39..fe8a7916e 100644
> --- a/Makerules
> +++ b/Makerules
> @@ -334,7 +334,7 @@ define link.so
>                 -Wl,-soname=$(notdir $@).$(2) \
>                 $(CFLAG_-nostdlib) $(CFLAG_-nostartfiles) \
>                 -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
> -               -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive
> \
> +               -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive
> -shared \
>                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
>         $(Q)$(LN) -sf $(1) $@.$(2)
>         $(Q)$(LN) -sf $(1) $@
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/Makerules b/Makerules
index 1a7443c39..fe8a7916e 100644
--- a/Makerules
+++ b/Makerules
@@ -334,7 +334,7 @@  define link.so
 		-Wl,-soname=$(notdir $@).$(2) \
 		$(CFLAG_-nostdlib) $(CFLAG_-nostartfiles) \
 		-o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
-		-Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \
+		-Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive -shared \
 		$(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
 	$(Q)$(LN) -sf $(1) $@.$(2)
 	$(Q)$(LN) -sf $(1) $@