From: Youling Tang <tangyouling@loongson.cn>
To: Xi Ruoyao <xry111@xry111.site>,
Jinyang He <hejinyang@loongson.cn>,
Huacai Chen <chenhuacai@kernel.org>
Cc: linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
Xuerui Wang <kernel@xen0n.name>,
Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH 1/3] LoongArch: tools: Add relocs tool support
Date: Thu, 8 Sep 2022 16:01:57 +0800 [thread overview]
Message-ID: <750719dc-d481-6eba-05c6-50cfdceb871b@loongson.cn> (raw)
In-Reply-To: <011b5d39-e0cb-69cc-66fd-ed46afe7695e@loongson.cn>
On 09/08/2022 10:44 AM, Youling Tang wrote:
> Hi, Ruoyao
>
> On 09/07/2022 06:19 PM, Youling Tang wrote:
>> Hi, Ruoyao
>>
>> On 09/06/2022 01:17 PM, Xi Ruoyao wrote:
>>> On Tue, 2022-09-06 at 10:16 +0800, Youling Tang wrote:
>>>
>>>> Switch to relative exception tables:
>>>>
>>>> https://github.com/tangyouling/linux/commit/6525b8da
>>>> https://github.com/tangyouling/linux/commit/b6ac0827
>>>>
>>>> Will switch to the relative exception tables after applying the above
>>>> two patches. So there is no need to relocate the exception table
>>>> (remove relocate_exception_table).
>>>>
>>>> Now we can remove the relocation of la.abs , got and ex_table, but
>>>> still need to relocate LARCH_64. Is there anything else that needs to
>>>> be modified to eliminate this relocation?
>>>
>>> You may see the RISC-V patch as a reference:
>>>
>>> https://lore.kernel.org/all/20211009171259.2515351-2-alexandre.ghiti@canonical.com/
>>>
>>>
>>>
>>> Basically, make the linker to generate R_*_RELATIVE instead of R_*_64
>>> for pointers. And, perform R_*_RELATIVE relocation loading the kernel.
>>>
>>> Something problematic IMO: RISC-V uses "-shared" to trick the linker to
>>> generate R_*_RELATIVE but I consider it ugly (if the kernel is a shared
>>> library, my grandma will be a wagon!) I prefer "-pie -static", but our
>>> Glibc does not have static-pie support for now. It won't really affect
>>> the kernel (we are -nostdlib), but we cannot learn how to handle
>>> R_*_RELATIVE in static pie from Glibc then.
>>>
>>
>> After applying all the patches in the link [1], the implementation of
>> the relocs tool can now be removed :).
>>
>> commit: 244fb0971a ... ad45233ef6
>>
>> [1] https://github.com/tangyouling/loongarch-next/commits/loongarch-next
>
> The previous LDFLAGS_vmlinux has not changed,
> LDFLAGS_vmlinux += -G0 -static -n -nostdlib
>
> When enabling CONFIG_RELOCATABLE to generate the PIE kernel, link
> vmliunx with different flags:
>
> 1)LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro
> This way is similar to arm64.
>
> The following warnings appear when linking when using the old toolchain
> (no warnings for the new toolchain):
>
> kernel/kallsyms.o(.text+0x4): warning: R_LARCH_SOP_PUSH_PCREL against
> [undefweak] `kallsyms_offsets':
> Undefweak need to be resolved dynamically, but PLT stub doesn't
> represent.
>
> 2)LDFLAGS_vmlinux += -pie
> No warnings appear, it looks fine together.
>
> I looked at some commits for arm64, at first arm64 used -pie -shared
> (direct link fails in LoongArch), Removed -pie after link [1] and only
> used -shared.
>
> [1]
> https://github.com/torvalds/linux/commit/3bbd3db86470c701091fb1d67f1fab6621debf50
>
After adding KBUILD_CFLAGS_KERNEL += -mdirect-extern-access, the kernel
will not generate .got, .plt and .got.plt sections (in the new
toolchain), we should unexpectedly detect that the kernel has these
sections, maybe add similar patch [1] to detect, x86_64 has the same
operation.
But when adding LDFLAGS_vmlinux += -pie (or -shared), there will be
.got, .plt and .got.plt sections generated, I don't know how the
toolchain handles it :(?
$ loongarch64-unknown-linux-gnu-readelf -S vmlinux
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 4] .plt PROGBITS 90000000010215e0 00e315e0
0000000000000040 0000000000000010 AX 0 0 16
[ 5] .got.plt PROGBITS 9000000001021620 00e31620
0000000000000020 0000000000000008 WA 0 0 8
[ 6] .got PROGBITS 9000000001021640 00e31640
0000000000000008 0000000000000008 WA 0 0 8
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=be2881824ae
Thanks,
Youling
next prev parent reply other threads:[~2022-09-08 8:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 10:08 [PATCH 0/3] Add kernel relocation and KASLR support Youling Tang
2022-09-02 10:08 ` [PATCH 1/3] LoongArch: tools: Add relocs tool support Youling Tang
2022-09-02 11:10 ` Xi Ruoyao
2022-09-02 11:27 ` Xi Ruoyao
2022-09-03 1:57 ` Youling Tang
2022-09-03 10:49 ` Xi Ruoyao
2022-09-03 16:23 ` Jinyang He
2022-09-03 16:53 ` Xi Ruoyao
2022-09-05 2:52 ` Youling Tang
2022-09-06 2:16 ` Youling Tang
2022-09-06 5:17 ` Xi Ruoyao
2022-09-07 10:19 ` Youling Tang
2022-09-08 2:44 ` Youling Tang
2022-09-08 8:01 ` Youling Tang [this message]
2022-09-22 11:19 ` Xi Ruoyao
2022-09-23 9:56 ` Youling Tang
2022-09-05 1:52 ` Youling Tang
2022-09-02 10:08 ` [PATCH 2/3] LoongArch: Add support for kernel relocation Youling Tang
2022-09-02 10:08 ` [PATCH 3/3] LoongArch: Add support for kernel address space layout randomization (KASLR) Youling Tang
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=750719dc-d481-6eba-05c6-50cfdceb871b@loongson.cn \
--to=tangyouling@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=hejinyang@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=xry111@xry111.site \
/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;
as well as URLs for NNTP newsgroup(s).