Skip to contentSkip to conversation

MIPS: tools: relocs: Ship a definition of R_MIPS_PC32

PATCH In review Yao Zi 4 participants 9 messages Feb 2 – Feb 5 MIPS

lore
Share & tools
lore

Yao Zi

author
#0 lore raw

PATCH 1/1 MIPS: tools: relocs: Ship a definition of R_MIPS_PC32

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Fixes ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux")
---
 arch/mips/boot/tools/relocs.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/mips/boot/tools/relocs.h +7 -0
index 607ff0103064..942981d9ce73 100644
@@ -29,6 +29,13 @@ void die(char *fmt, ...);
 #define R_MIPS_PC26_S2		61
 #endif
 
+/*
+ * GNU extension that available in glibc only since 2023, not available on musl.
+ */
+#ifndef R_MIPS_PC32
+#define R_MIPS_PC32		248
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 enum symtype {
Signature · 1 line
2.52.0
#1 lore raw
Quoted 7 lines · Yao Zi

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Fixes ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux")

Thanks for fixing this.

It does imply that the subsequent kallsyms patch will result in 32-bit MIPS no longer being buildable with older toolchains if CONFIG_RELOCATABLE=y.

Not sure if that is an issue, but it needs calling out. Nathan, any thoughts?

Quoted 25 lines
---
 arch/mips/boot/tools/relocs.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/mips/boot/tools/relocs.h +2 -0
index 607ff0103064..942981d9ce73 100644
@@ -29,6 +29,13 @@ void die(char *fmt, ...);
 #define R_MIPS_PC26_S2		61
 #endif
 
+/*
+ * GNU extension that available in glibc only since 2023, not 

available on musl.
+ */

arch/mips/boot/tools/relocs.h +4 -0
+#ifndef R_MIPS_PC32
+#define R_MIPS_PC32		248
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 enum symtype {
Signature · 1 line
2.52.0
#2 lore raw
Quoted 7 lines · Ard Biesheuvel
Quoted 5 lines · Yao Zi

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Quoted 6 lines
Quoted 2 lines
Fixes ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux")

Thanks for fixing this.

It does imply that the subsequent kallsyms patch will result in 32-bit MIPS no longer being buildable with older toolchains if CONFIG_RELOCATABLE=y.

Doing a little research, it seems like R_MIPS_PC32 has been recognized by the toolchains for a long time, as I found these commits in binutils:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=092dcd755dcdcf664b25a7011fd15957f124c29f
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b47468a6dbd1b54c44c2edc0f7db64a073d894ea

It seems like this relocation was not documented in glibc until recently, along with many other relocation types:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a6e8ceb3bb532236e1eecd0bb0ee8e4b7fd5ff7c

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

If we get an obvious build breakage report down the road, we can always add another forward fix or back out of the changes altogether.

Quoted 27 lines

Not sure if that is an issue, but it needs calling out. Nathan, any thoughts?

Quoted 25 lines
---
 arch/mips/boot/tools/relocs.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/mips/boot/tools/relocs.h +2 -0
index 607ff0103064..942981d9ce73 100644
@@ -29,6 +29,13 @@ void die(char *fmt, ...);
 #define R_MIPS_PC26_S2		61
 #endif
 
+/*
+ * GNU extension that available in glibc only since 2023, not 

available on musl.
+ */

arch/mips/boot/tools/relocs.h +4 -0
+#ifndef R_MIPS_PC32
+#define R_MIPS_PC32		248
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 enum symtype {
Signature · 1 line
2.52.0
author
#3 lore raw
Quoted 24 lines · Nathan Chancellor
Quoted 7 lines · Ard Biesheuvel
Quoted 5 lines · Yao Zi

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Quoted 6 lines
Quoted 2 lines
Fixes ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux")

Thanks for fixing this.

It does imply that the subsequent kallsyms patch will result in 32-bit MIPS no longer being buildable with older toolchains if CONFIG_RELOCATABLE=y.

Doing a little research, it seems like R_MIPS_PC32 has been recognized by the toolchains for a long time, as I found these commits in binutils:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=092dcd755dcdcf664b25a7011fd15957f124c29f
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b47468a6dbd1b54c44c2edc0f7db64a073d894ea

It seems like this relocation was not documented in glibc until recently, along with many other relocation types:

Quoted 7 lines

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a6e8ceb3bb532236e1eecd0bb0ee8e4b7fd5ff7c

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

Yes, this patch is only meant to fix building of relocs tool. I don't think there are problems about toolchain supporting since R_MIPS_PC32 has been in binutils for a long time, as Nathan found, since 2004. The situation is that it's likely to have a toolchain supporting R_MIPS_PC32, while elf.h on the build machine doesn't have its definition. And after ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), the relocs tool started to require a definition of R_MIPS_PC32 to build.

Quoted 5 lines

If we get an obvious build breakage report down the road, we can always add another forward fix or back out of the changes altogether.

Quoted 2 lines

Not sure if that is an issue, but it needs calling out. Nathan, any thoughts?

Best regards,
Yao Zi

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
---
 arch/mips/boot/tools/relocs.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/mips/boot/tools/relocs.h +2 -0
index 607ff0103064..942981d9ce73 100644
@@ -29,6 +29,13 @@ void die(char *fmt, ...);
 #define R_MIPS_PC26_S2		61
 #endif
 
+/*
+ * GNU extension that available in glibc only since 2023, not 

available on musl.
+ */

arch/mips/boot/tools/relocs.h +4 -0
+#ifndef R_MIPS_PC32
+#define R_MIPS_PC32		248
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 enum symtype {
Signature · 1 line
2.52.0
#4 lore raw
Quoted 33 lines · Yao Zi
Quoted 24 lines · Nathan Chancellor
Quoted 7 lines · Ard Biesheuvel
Quoted 5 lines · Yao Zi

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Quoted 6 lines
Quoted 2 lines
Fixes ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux")

Thanks for fixing this.

It does imply that the subsequent kallsyms patch will result in 32-bit MIPS no longer being buildable with older toolchains if CONFIG_RELOCATABLE=y.

Doing a little research, it seems like R_MIPS_PC32 has been recognized by the toolchains for a long time, as I found these commits in binutils:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=092dcd755dcdcf664b25a7011fd15957f124c29f
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b47468a6dbd1b54c44c2edc0f7db64a073d894ea

It seems like this relocation was not documented in glibc until recently, along with many other relocation types:

Quoted 7 lines

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a6e8ceb3bb532236e1eecd0bb0ee8e4b7fd5ff7c

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

Quoted 9 lines

Yes, this patch is only meant to fix building of relocs tool. I don't think there are problems about toolchain supporting since R_MIPS_PC32 has been in binutils for a long time, as Nathan found, since 2004. The situation is that it's likely to have a toolchain supporting R_MIPS_PC32, while elf.h on the build machine doesn't have its definition. And after ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), the relocs tool started to require a definition of R_MIPS_PC32 to build.

OK, thanks for the clarification.

#5 lore raw
In reply to Yao Zi
Quoted 9 lines · Yao Zi
Quoted 5 lines

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

Yes, this patch is only meant to fix building of relocs tool. I don't think there are problems about toolchain supporting since R_MIPS_PC32 has been in binutils for a long time, as Nathan found, since 2004. The

Since Y2K to be exact:

commit bb2d6cd7b19cd82313963d2d878a94e6e85a38b6

Author: Geoffrey Keating <[email protected]>
Date:   Sat Mar 11 02:16:25 2000 +0000

[...]
In include/elf:
* mips.h: Add R_MIPS_GNU_REL_HI16, R_MIPS_GNU_REL_LO16, R_MIPS_GNU_REL16_S2, R_MIPS_PC64 and R_MIPS_PC32 relocation numbers.

Quoted 5 lines

situation is that it's likely to have a toolchain supporting R_MIPS_PC32, while elf.h on the build machine doesn't have its definition. And after ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), the relocs tool started to require a definition of R_MIPS_PC32 to build.

But where does ff79d31eb536 come from? I can't see it on Linus's master
and you can't refer an SHA-1 ID from another repo in a 'Fixes:' tag AFAIK, as it's going to change as a commit is merged. Also can't you get the fix folded into the offending commit since it hasn't been merged yet?

Maciej

author
#6 lore raw
Quoted 30 lines · Maciej W. Rozycki
Quoted 9 lines · Yao Zi
Quoted 5 lines

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

Yes, this patch is only meant to fix building of relocs tool. I don't think there are problems about toolchain supporting since R_MIPS_PC32 has been in binutils for a long time, as Nathan found, since 2004. The

Since Y2K to be exact:

commit bb2d6cd7b19cd82313963d2d878a94e6e85a38b6

Author: Geoffrey Keating <[email protected]>
Date:   Sat Mar 11 02:16:25 2000 +0000

[...]
In include/elf:
* mips.h: Add R_MIPS_GNU_REL_HI16, R_MIPS_GNU_REL_LO16, R_MIPS_GNU_REL16_S2, R_MIPS_PC64 and R_MIPS_PC32 relocation numbers.

Quoted 5 lines

situation is that it's likely to have a toolchain supporting R_MIPS_PC32, while elf.h on the build machine doesn't have its definition. And after ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), the relocs tool started to require a definition of R_MIPS_PC32 to build.

Quoted 3 lines

But where does ff79d31eb536 come from? I can't see it on Linus's master
and you can't refer an SHA-1 ID from another repo in a 'Fixes:' tag AFAIK, as it's going to change as a commit is merged.

This commit has been in kbuild/kbuild-next for some time[1], and has broken linux-next MIPS builds on my machine.

Quoted 2 lines

Also can't you get the fix folded into the offending commit since it hasn't been merged yet?

I'm not the author of ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), and though it hasn't reached Linus' master, it has been merged into kbuild-next.

I'm fine with it if the maintainer considers it necessary to squash them together.

Quoted 1 line

Maciej

Thanks,
Yao Zi

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git/commit/?id=ff79d31eb536f6d87bcbc09287d54d5606bf6dbe

#7 lore raw
In reply to Maciej W. Rozycki
Quoted 24 lines · Maciej W. Rozycki
Quoted 9 lines · Yao Zi
Quoted 5 lines

I interpret that to mean that the kallsyms patch should work fine since the toolchain can handle these relocations? It is just building the relocs tool against an older glibc or musl that does not have the R_MIPS_PC32 definition that is broken? Or am I misunderstanding something?

Yes, this patch is only meant to fix building of relocs tool. I don't think there are problems about toolchain supporting since R_MIPS_PC32 has been in binutils for a long time, as Nathan found, since 2004. The

Since Y2K to be exact:

commit bb2d6cd7b19cd82313963d2d878a94e6e85a38b6

Author: Geoffrey Keating <[email protected]>
Date:   Sat Mar 11 02:16:25 2000 +0000

[...]
In include/elf:
* mips.h: Add R_MIPS_GNU_REL_HI16, R_MIPS_GNU_REL_LO16, R_MIPS_GNU_REL16_S2, R_MIPS_PC64 and R_MIPS_PC32 relocation numbers.

Quoted 8 lines
Quoted 5 lines

situation is that it's likely to have a toolchain supporting R_MIPS_PC32, while elf.h on the build machine doesn't have its definition. And after ff79d31eb536 ("mips: Add support for PC32 relocations in vmlinux"), the relocs tool started to require a definition of R_MIPS_PC32 to build.

But where does ff79d31eb536 come from? I can't see it on Linus's master
and you can't refer an SHA-1 ID from another repo in a 'Fixes:' tag AFAIK,

Yes, you can, as long as the owner of the tree does not rebase.

#8 lore raw
In reply to Yao Zi
Quoted 6 lines · Yao Zi

R_MIPS_PC32 is a GNU extension, its definition is available in glibc only since 2.39 (released in 2024), and not available in musl libc yet. Provide our own definition for R_MIPS_PC32 and use it if necessary to fix relocs tool building on musl and older glibc systems.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next

Thanks!

[1/1] MIPS: tools: relocs: Ship a definition of R_MIPS_PC32

      https://git.kernel.org/kbuild/c/87abe931fbc34

Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.

Best regards,

Signature · 1 line
Nathan Chancellor <[email protected]>