Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Add new relocation type support #57

Merged
merged 1 commit into from
Jul 25, 2022
Merged

Conversation

cloudspurs
Copy link

No description provided.

@xen0n
Copy link
Contributor

xen0n commented Jul 17, 2022

Isn't there already #50? You may want to consider my suggestions there (and I submitted #56 for official approval) as naming is very important.

|67
|R_LARCH_ABS_HI20
|32 位绝对地址的[12:31]位
|`(*(uint32_t *) PC) [24 ... 5] = (S+A) [31 ... 12]+`
Copy link
Contributor

@xry111 xry111 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does these extra + mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have modified


|71
|R_LARCH_PCALA_HI20
|32位相对PC偏移的[12:31]位
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description seems different than the symbolic definition below. Say PC is 0x0f00 and (S + A) is 0x1000, (((S+A) & ~0xfff) - (PC & ~0xfff)) [31 ... 12] will be 0x1000 but the PC-relative offset will be 0x0100, and "the [12:31] bits of PC-relative offset" will be zero.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added additional explanation: "all PC-relative offset calculations do not include the lowest 12 bits".


|100
|R_LARCH_RELAX
|暂未实现
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's not implemented, you should give it a definition. Otherwise you should just leave it undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relocation is expected to do some optimizations, do or not won't affect correctness.
The linker has implemented some specific instructions, but the assembler still has some support that has not been completed.
If it is deleted, the current version linker can not to link next version object (maybe soon to be patched).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe a simple description like "mark a instruction suitable for link-time relaxation" or something (does @xen0n have a better idea?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sym - pc >= 0xffe00000 && sym -pc <= 0x1ffffc
can do relax:
pcalau12i $r12, sym
addi.d $r12, $r12, sym
=>
pcaddi $r12, sym
nop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: make sure you all read MaskRay's excellent writeups on the topic of linker relaxations before implementing any of these. ;-)

Copy link
Contributor

@xry111 xry111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we ignore the debateful naming part, and we don't care "human ego" of reviewers outside Loongson, I don't think we can merge this in status quo. If you allow me to speak candidly: this just seems like a scratch paper where somebody wrote some random thoughts, instead of a formal technical documentation.

|72
|R_LARCH_PCALA_LO12
|32位相对PC偏移的[0:11]位
|`(*(uint32_t *) PC) [21 ... 10] = (S+A) [11 ... 0]+`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text description is completely different than the symbolic definition. The symbolic description is exactly same as R_LARCH_ABS_LO12.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you want to use something like:

pcalau12i $t0, %pcala_hi20(something)
ld.d $t0, $t0, %lo12(something)

to load something, if I interpret @SixWeining's comment in https://reviews.llvm.org/D128427 correctly. Then, (1) you don't need a separate "%pcala_lo12" (it's same as "%abs_lo12" so only one "%lo12" is enough); (2) you need to alter the definition of %pcala_hi20 to account the carry from %lo12 into consideration. Like:

R_LARCH_PCALA_HI20 ::= (*(u32 *)PC) [24..5] = (((S+A+0x800) & ~0xfff) - (PC & ~0xfff))[31..12]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R_LARCH_ABS_LO12 and R_LARCH_PCALA_LO12 are calculated in the same way. Only take the lower 12 bits without other operations. In earlier versions it was the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an error and has been modified.

@xry111
Copy link
Contributor

xry111 commented Jul 20, 2022

It's better to consistently use [a..b] or [a:b] notion, instead of mixing up Python-style [a:b] notion with Rust-style [a..b] notion.

@ChenghuaXu
Copy link
Contributor

It's better to consistently use [a..b] or [a:b] notion, instead of mixing up Python-style [a:b] notion with Rust-style [a..b] notion.

@cloudspurs

@cloudspurs cloudspurs force-pushed the new-reloc branch 3 times, most recently from 0056438 to 2800362 Compare July 21, 2022 08:14
@xen0n
Copy link
Contributor

xen0n commented Jul 21, 2022

On a related note, what does the "ALA" in "PCALA" mean? I don't think we've seen any full form anywhere for this abbreviation.

Comment on lines +698 to +699
|[31 ... 12] bits of 32/64-bit PC-relative offset
|`+(*(uint32_t *) PC) [24 ... 5] = (((S+A) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|[31 ... 12] bits of 32/64-bit PC-relative offset
|`+(*(uint32_t *) PC) [24 ... 5] = (((S+A) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+`
|[31 ... 12] bits of 32/64-bit PC-relative offset to the nearest 4KB bounary for the target
|`+(*(uint32_t *) PC) [24 ... 5] = (((S+A+0x800) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+`

For example, S+A = 0x12001800 and PC = 0x12000010. We want:

pcalau12i $t0, 0x2   # 0x2000 >> 12
addi.d $t0, $t0, 0x800 # -2048

to get S+A. Without +0x800 we get pcalau12i $t0, $0x1 then we can't use addi.d (ori is needed for a positive offset >= 2048). But the binutils patch uses addi.d, not ori.

Copy link
Contributor

@lzshhxx lzshhxx Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcalau12i $t0, 0x2 # (S+A+0x800)&(~0xfff) - (PC & (~0xfff))

Comment on lines +740 to +748
|79
|R_LARCH_GOT_HI20
|GOT 表项 32/64 位绝对地址的 [31 ... 12] 位
|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G) [31 ... 12]+`

|80
|R_LARCH_GOT_LO12
|GOT 表项 32/64 位绝对地址的 [11 ... 0] 位
|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [11 ... 0]+`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of 79 and 80 are not the same as in the code, which is correct?

The names in the binutils code are:

R_LARCH_GOT64_HI20 79
R_LARCH_GOT64_LO12 80

https://github.com/loongson/binutils-gdb/blob/291cb57c2947868201be6c2b0b903d318a7df90d/include/elf/loongarch.h#L161

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ChenghuaXu ChenghuaXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@ChenghuaXu ChenghuaXu merged commit 363cc96 into loongson:main Jul 25, 2022
@xen0n
Copy link
Contributor

xen0n commented Jul 25, 2022

@xry111 hasn't approved, why merge?

@xry111
Copy link
Contributor

xry111 commented Jul 25, 2022

See #58 for a fix of "details" for PC-relative relocs.

gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Aug 7, 2022
gcc-13 has been pretty stable over the weeks I have been using it, so
keyword one latest gcc-13 snapshot for wider testing. This should bring
the entire loong world to make use of the new-style relocs [1] [2].

Currently the loong kernel cannot be natively built with such a
toolchain combination, but a fix is in the works [3]. Because no Gentoo
kernel source package has been keyworded ~loong, and the current
userbase can be effectively notified in other ways (the Telegram
Loongson user group for example), I decided to proceed with the
keywording to enable widespread testing of the fresh loong code. The
various toolchain projects all cut their releases just recently so we
should have plenty of time to polish things before the next big release.

[1]: loongson/LoongArch-Documentation#57
[2]: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=6d13722a97cee3fd397e116bde3bcedbb1e220be;hp=5d471bd907be60e9858b22cdf4fd10ddc0f6ee1a
[3]: https://lore.kernel.org/loongarch/CAAhV-H7oQkGVqZV_s7tXjDGBL9yQ+CsUkCv7tC+pWuW2MXe9LA@mail.gmail.com/T/#me74ccdafb0d98d5d13fa2a82356ec5dff1a49a89

Signed-off-by: WANG Xuerui <[email protected]>
gopherbot pushed a commit to golang/go that referenced this pull request Aug 11, 2022
LoongArch ELF psABI spec update:
loongson/LoongArch-Documentation#57

Corresponding binutils implementation:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6d13722a97cee3fd397e116bde3bcedbb1e220be
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9801120721c3a702ce3bd50433ef920f92a83502

For #54222

Change-Id: I51e72294205847a69c01d741a3126248f7a7e41c
Reviewed-on: https://go-review.googlesource.com/c/go/+/420982
Reviewed-by: Meng Zhuo <[email protected]>
Run-TryBot: Meng Zhuo <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: abner chenc <[email protected]>
@Eldeloro1
Copy link

No description provided.

intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request Aug 27, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request Aug 29, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
xry111 added a commit to xry111/linux that referenced this pull request Aug 30, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request Aug 30, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
xry111 added a commit to xry111/linux that referenced this pull request Sep 3, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
xen0n pushed a commit to xen0n/linux that referenced this pull request Sep 4, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
xen0n pushed a commit to xen0n/linux that referenced this pull request Sep 5, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
yetist added a commit to loongarch64-archive/grub that referenced this pull request Sep 9, 2022
yetist added a commit to loongarch64-archive/grub that referenced this pull request Sep 9, 2022
xry111 added a commit to xry111/linux that referenced this pull request Sep 22, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
it-is-a-robot pushed a commit to openeuler-mirror/kernel that referenced this pull request Sep 30, 2022
LoongArch inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB

--------------------------------

These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
it-is-a-robot pushed a commit to openeuler-mirror/kernel that referenced this pull request Sep 30, 2022
LoongArch inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB

--------------------------------

These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
mj22226 pushed a commit to mj22226/linux that referenced this pull request Sep 30, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
mpe pushed a commit to linuxppc/linux-ci that referenced this pull request Oct 4, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
jessfraz pushed a commit to jessfraz/linux that referenced this pull request Oct 11, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
jessfraz pushed a commit to jessfraz/linux that referenced this pull request Oct 12, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
torvalds pushed a commit to torvalds/linux that referenced this pull request Oct 12, 2022
These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Tested-by: WANG Xuerui <[email protected]>
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
it-is-a-robot pushed a commit to openeuler-mirror/kernel that referenced this pull request Nov 30, 2022
LoongArch inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB

--------------------------------

These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
it-is-a-robot pushed a commit to openeuler-mirror/kernel that referenced this pull request Dec 6, 2022
LoongArch inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB

--------------------------------

These relocation types are used by GNU binutils >= 2.40 and GCC >= 13.
Add their definitions so we will be able to use them in later patches.

Link: loongson/LoongArch-Documentation#57
Signed-off-by: Xi Ruoyao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants