ldso: Force disable -mlong-calls when compiling ldso for ARC
PATCH 1/1 ldso: Force disable -mlong-calls when compiling ldso for ARC
Even though by default for ARC uClibc gets compiled with disabled long-calls user may provide UCLIBC_EXTRA_CFLAGS with "-mlong-calls". With this option uClibc will be successfully compiled but later it will fail in runtime because dynamic loader cannot deal with relocations at least very early on its start.
In particular it will be seen as call to non-relocated symbol _dl_parse_dynamic_info() which ends-up as a segfault like this:
------------------------>8-------------------- potentially unexpected fatal signal 11.
Path: /bin/test
CPU: 0 PID: 63 Comm: test Not tainted 4.5.2 #7 task: 9f13f180 ti: 9f166000 task.ti: 9f166000
[ECR ]: 0x00040000 => Insn could not be fetched
[EFA ]: 0x0000283c
[BLINK ]: 0x2000407c
[ERET ]: 0x283c
@No matching VMA found
[STAT32]: 0x8008009e : IE U
BTA: 0x0000283c SP: 0x5fef5ccc FP: 0x00000000
LPS: 0x20004080 LPE: 0x20004064 LPC: 0x00000000
r00: 0x20006684 r01: 0x5fef5db0 r02: 0x00000000
r03: 0x20000000 r04: 0x80808080 r05: 0x2f2f2f2f
r06: 0x41464d00 r07: 0x00000080 r08: 0x000000dd
r09: 0x00000000 r10: 0x00000073 r11: 0x80808080
r12: 0x2000407c r13: 0x20000000 r14: 0x5fef5e74
r15: 0x000ceb3c r16: 0x5fef5e7c r17: 0x5fef5d44
r18: 0x000ceb0c r19: 0xffffffff r20: 0x000ceb1c
r21: 0x00000000 r22: 0x00000000 r23: 0x000d08a5
r24: 0x00000000 r25: 0x80808080
Segmentation fault ------------------------>8--------------------
Solution to this issue is simple we make sure dynamic loader never gets compiled with "-mlong-calls" by forcing "-mno-long-calls" on it.
--- ldso/ldso/Makefile.in | 4 ++++ 1 file changed, 4 insertions(+)
ldso/ldso/Makefile.in +4 -0
@@ -34,6 +34,10 @@ CFLAGS-$(DODEBUG)-ldso/ldso := -O2 -g CFLAGS-ldso.c := -DLDSO_ELFINTERP=\"$(TARGET_ARCH)/elfinterp.c\" +ifeq ($(TARGET_ARCH),arc) +CFLAGS-ldso.c += -mno-long-calls +endif + LDFLAGS-$(UCLIBC_FORMAT_DSBT_ELF)-$(UCLIBC_LDSO_NAME).so := -Wl,--dsbt-index=1 ifneq ($(SUPPORT_LD_DEBUG),y) LDFLAGS-$(UCLIBC_LDSO_NAME).so := $(LDFLAGS)
Signature · 1 line
2.5.5
PATCH 1/1 ldso: Force disable -mlong-calls when compiling ldso for ARC
Quoted 55 lines · Alexey Brodkin
Even though by default for ARC uClibc gets compiled with disabled long-calls user may provide
UCLIBC_EXTRA_CFLAGSwith "-mlong-calls". With this option uClibc will be successfully compiled but later it will fail in runtime because dynamic loader cannot deal with relocations at least very early on its start.In particular it will be seen as call to non-relocated symbol
_dl_parse_dynamic_info()which ends-up as a segfault like this:
------------------------>8-------------------- potentially unexpected fatal signal 11.
Path:/bin/testCPU: 0 PID: 63 Comm: test Not tainted 4.5.2 #7 task: 9f13f180 ti: 9f166000 task.ti: 9f166000[ECR ]:
0x00040000=> Insn could not be fetched
[EFA ]:0x0000283c
[BLINK ]:0x2000407c
[ERET ]:0x283c
@No matching VMA found
[STAT32]:0x8008009e: IE U
BTA:0x0000283cSP:0x5fef5cccFP:0x00000000
LPS:0x20004080LPE:0x20004064LPC:0x00000000
r00:0x20006684r01:0x5fef5db0r02:0x00000000
r03:0x20000000r04:0x80808080r05:0x2f2f2f2f
r06:0x41464d00r07:0x00000080r08:0x000000dd
r09:0x00000000r10:0x00000073r11:0x80808080
r12:0x2000407cr13:0x20000000r14:0x5fef5e74
r15:0x000ceb3cr16:0x5fef5e7cr17:0x5fef5d44
r18:0x000ceb0cr19:0xffffffffr20:0x000ceb1c
r21:0x00000000r22:0x00000000r23:0x000d08a5
r24:0x00000000r25:0x80808080Segmentation fault ------------------------>8--------------------
Solution to this issue is simple we make sure dynamic loader never gets compiled with "-mlong-calls" by forcing "-mno-long-calls" on it.
Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>Cc Vineet Gupta <vgupta at synopsys.com>Cc Anton Kolesov <akolesov at synopsys.com>Cc linux-snps-arc at lists.infradead.org--- ldso/ldso/Makefile.in | 4 ++++ 1 file changed, 4 insertions(+)ldso/ldso/Makefile.in +0
-0
ldso/ldso/Makefile.in CFLAGS-$(DODEBUG)-ldso/ldso := -O2 -g · line 43
Quoted 10 lines
ldso/ldso/Makefile.in +4
-0@@ -34,6 +34,10 @@ CFLAGS-$(DODEBUG)-ldso/ldso := -O2 -g CFLAGS-ldso.c := -DLDSO_ELFINTERP=\"$(TARGET_ARCH)/elfinterp.c\" +ifeq ($(TARGET_ARCH),arc) +CFLAGS-ldso.c += -mno-long-calls +endif + LDFLAGS-$(UCLIBC_FORMAT_DSBT_ELF)-$(UCLIBC_LDSO_NAME).so := -Wl,--dsbt-index=1 ifneq ($(SUPPORT_LD_DEBUG),y) LDFLAGS-$(UCLIBC_LDSO_NAME).so := $(LDFLAGS)
This change is fine, but changelog could be improved based on some commentary below.
so uClibc ldso - atleast as it builds/works for ARC, doesn't have any PLT calls for it's own code. Most of it is built as a single compilation unit and in the final link all function calls are resolved to be within the dso thus eliding need for any PLT calls. Hence there is no code to fixup PLT as it doesn't exist for ldso (which probably other arches do).
But one of the side effects of building with -fPIC -mlong-calls is that gcc/gas start generating PLT calls.
So while we used to get before
6006 3e5e: 0f76 ff2f bl.d 25d0 <_dl_parse_dynamic_info>
Now becomes
5894 41fa: 2730 7f8c 0000 2a8c ld r12,[pcl,0x2a8c] 5895 4202: 7c60 jl_s.d [r12]
This is fine for normal dso's as GOT slot for functions will be fixed up lazily or now , but not for ldso itself. Hence the need for building ldso explciitly with -mno-long-calls
HTH,
-Vineet
PATCH 1/1 ldso: Force disable -mlong-calls when compiling ldso for ARC
In reply to Alexey BrodkinHi Alexey,
Alexey Brodkin wrote,
Quoted 37 lines
Even though by default for ARC uClibc gets compiled with disabled long-calls user may provide
UCLIBC_EXTRA_CFLAGSwith "-mlong-calls". With this option uClibc will be successfully compiled but later it will fail in runtime because dynamic loader cannot deal with relocations at least very early on its start.In particular it will be seen as call to non-relocated symbol
_dl_parse_dynamic_info()which ends-up as a segfault like this:
------------------------>8-------------------- potentially unexpected fatal signal 11.
Path:/bin/testCPU: 0 PID: 63 Comm: test Not tainted 4.5.2 #7 task: 9f13f180 ti: 9f166000 task.ti: 9f166000[ECR ]:
0x00040000=> Insn could not be fetched
[EFA ]:0x0000283c
[BLINK ]:0x2000407c
[ERET ]:0x283c
@No matching VMA found
[STAT32]:0x8008009e: IE U
BTA:0x0000283cSP:0x5fef5cccFP:0x00000000
LPS:0x20004080LPE:0x20004064LPC:0x00000000
r00:0x20006684r01:0x5fef5db0r02:0x00000000
r03:0x20000000r04:0x80808080r05:0x2f2f2f2f
r06:0x41464d00r07:0x00000080r08:0x000000dd
r09:0x00000000r10:0x00000073r11:0x80808080
r12:0x2000407cr13:0x20000000r14:0x5fef5e74
r15:0x000ceb3cr16:0x5fef5e7cr17:0x5fef5d44
r18:0x000ceb0cr19:0xffffffffr20:0x000ceb1c
r21:0x00000000r22:0x00000000r23:0x000d08a5
r24:0x00000000r25:0x80808080Segmentation fault ------------------------>8--------------------
Quoted 8 lines
Solution to this issue is simple we make sure dynamic loader never gets compiled with "-mlong-calls" by forcing "-mno-long-calls" on it.
Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>Cc Vineet Gupta <vgupta at synopsys.com>Cc Anton Kolesov <akolesov at synopsys.com>Cc linux-snps-arc at lists.infradead.org
applied and pushed,
Thanks
Waldemar