You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SRSO] mitigations cause unable to move location counter backward for: .text for LTO #1909
@samitolvanen and I had a conversation about this on internal chat:
me:
I'm getting some odd results where the linker script has:.text {
*(.text.__x86.rethunk_untrain)
__entry_text_start = .
__entry_text_end = .
*(.text.__x86.rethunk_safe)
}
but with LTO somehow the symbols from the two retunk sections have addresses both less than the two __entry symbols
I wonder if TEXT_MAIN is matching those rethunks. include/asm-generic/vmlinux.lds.h L99
sami:
Maybe .text.__x86* gets merged into .text
Exactly
Needs double dots
me:
#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*would .text.__x86.rethunk_untrain match that though?
shouldn't the third . in .text.__x86.rethunk_untrain fail to match?
sami:
Good point, the second dot shouldn't match
Then again, the regex doesn't specify the end, so depends on how it's used
It matches the .text.__x86 part
Not sure how the linker handles it
on a hunch, I tried simply renaming the section and that seems to fix this.
I'm trying to remember if globbing rules for input sections in linker scripts came up before.
Perhaps this should be fixed in LLD? It's surprising to me that .text.[0-9a-zA-Z_]* would match .text.__x86.rethunk_untrain. Otherwise perhaps we need to be more specific with our regex here
# foo.lds
PHDRS {
text PT_LOAD ;
}
SECTIONS {
.text : {
*(.text .text.[0-9]*)
} : text
}
$ clang y.c -Wl,-T,foo.lds -O0 -fuse-ld=bfd -Wl,--orphan-handling=warn 2>&1 | grep text
$
$ llvm-nm a.out | grep -e foo -e bar
00000000000003dc T bar2
00000000000003e0 T foo2
So bar2 was defined first in section .text.10.hot and foo2 in .text.10. Without the linker script, I'd have expected all linkers to lay out bar2 then foo2 (so that bar2 has a lower address than foo2).
With the addition of the linker script and my knowledge of how regexes work (apparently everywhere BUT linkerscripts), I'd have expected:
.text.10 to be matched by .text.[0-9]* (thus moving foo2 first)
-Wl-,--orphan-handling=warn to warn that .text.10.hot was considered an orphan, since it wasn't explicitly placed and did not match .text.[0-9]* due to the third dot in .text.10.hot.
Instead, we get the unexpected order:
$ clang y.c -Wl,-T,foo.lds -O0 -fuse-ld=bfd -Wl,--orphan-handling=warn 2>&1 | grep text
$ llvm-nm a.out | grep -e foo -e bar
00000000000003dc T bar2
00000000000003e0 T foo2
Where bar2 comes //after// foo2, and no orphan section warning. This happens even if I:
change -fuse-ld=bfd to -fuse-ld=lld
change -fuse-ld=bfd to -fuse-ld=lld -flto=thin
I swear @MaskRay explained this to us once before somewhere...but those experiments make it look to me less like any kind of bug in LLD and more like a general hazard when using globbing rules on input sections in linker scripts.
I'm not sure this surprising behavior is documented
changed the title [-]SRSO mitigations cause `unable to move location counter backward for: .text` for LTO[/-][+][SRSO] mitigations cause `unable to move location counter backward for: .text` for LTO[/+]on Aug 10, 2023
It has been backported to 6.4 so far but it should go back to 6.1 and 5.15, it appears the conflicts/issues with all the SRSO fixes have delayed these backports past 6.4 for now.
Activity
nickdesaulniers commentedon Aug 9, 2023
@samitolvanen and I had a conversation about this on internal chat:
on a hunch, I tried simply renaming the section and that seems to fix this.
And that works:
I'm trying to remember if globbing rules for input sections in linker scripts came up before.
Perhaps this should be fixed in LLD? It's surprising to me that
.text.[0-9a-zA-Z_]*would match.text.__x86.rethunk_untrain. Otherwise perhaps we need to be more specific with our regex herenathanchance commentedon Aug 9, 2023
Ha, I think this series might need to be fast tracked and be updated for SRSO...
https://lore.kernel.org/[email protected]/
EDIT: Or at least the first patch.
nathanchance commentedon Aug 9, 2023
Yeah, that series is in -next and I can see that Stephen fixed up the merge conflict with respect to SRSO:
https://lore.kernel.org/[email protected]/
If I apply the proposed fix for #1907 on top of
next-20230809, I don't see an error withARCH=x86_64 defconfig+CONFIG_LTO_CLANG_THIN=yany more.nickdesaulniers commentedon Aug 9, 2023
FWICT, it seems like LLD matches the behavior of BFD for globbing.
So
bar2was defined first in section.text.10.hotandfoo2in.text.10. Without the linker script, I'd have expected all linkers to lay outbar2thenfoo2(so thatbar2has a lower address thanfoo2).With the addition of the linker script and my knowledge of how regexes work (apparently everywhere BUT linkerscripts), I'd have expected:
.text.10to be matched by.text.[0-9]*(thus movingfoo2first)-Wl-,--orphan-handling=warnto warn that.text.10.hotwas considered an orphan, since it wasn't explicitly placed and did not match.text.[0-9]*due to the third dot in.text.10.hot.Instead, we get the unexpected order:
Where
bar2comes //after//foo2, and no orphan section warning. This happens even if I:-fuse-ld=bfdto-fuse-ld=lld-fuse-ld=bfdto-fuse-ld=lld -flto=thinI swear @MaskRay explained this to us once before somewhere...but those experiments make it look to me less like any kind of bug in LLD and more like a general hazard when using globbing rules on input sections in linker scripts.
I'm not sure this surprising behavior is documented
Ah, yeah! That looks like the same issue and sfr has fixed it in the new places, too. That fixed up version resolves the issue for me.
Boris also mentioned on IRC:
Though what's in tip is the old/broken version
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=973ab2d61f33dc85212c486e624af348c4eeb5c9
that needs sfr's fixes
https://lore.kernel.org/all/[email protected]/
nathanchance commentedon Aug 9, 2023
I have pushed https://github.com/ClangBuiltLinux/linux/commits/srso-fixes for testing.
[-]SRSO mitigations cause `unable to move location counter backward for: .text` for LTO[/-][+][SRSO] mitigations cause `unable to move location counter backward for: .text` for LTO[/+]nickdesaulniers commentedon Aug 10, 2023
I've left this message to Boris on IRC:
customization: 6.1.44-moe / 6.4.9-moe
customization: 6.1.44-moe / 6.4.9-moe
nathanchance commentedon Aug 14, 2023
Patch has been picked up in
x86/urgent: https://git.kernel.org/tip/79cd2a11224eab86d6673fe8a11d2046ae9d2757patch: fix LTO build with SRSO
[Patch] Switch to LLVM-git and Fix Clang Build (#40)
nathanchance commentedon Aug 23, 2023
The fix is now in mainline: https://git.kernel.org/linus/79cd2a11224eab86d6673fe8a11d2046ae9d2757
It has been backported to 6.4 so far but it should go back to 6.1 and 5.15, it appears the conflicts/issues with all the SRSO fixes have delayed these backports past 6.4 for now.
nickdesaulniers commentedon Aug 23, 2023
Do we want to keep this open to track backports?
nathanchance commentedon Aug 23, 2023
Sure.
nathanchance commentedon Aug 24, 2023
Stable patches out for review.
6.1: https://lore.kernel.org/[email protected]/
5.15: https://lore.kernel.org/[email protected]/
nathanchance commentedon Aug 28, 2023
Now released in stable kernels:
6.1: https://git.kernel.org/stable/c/c8b056a3b4ebb33adbb873cab152ed499d1a1dcb
5.15: https://git.kernel.org/stable/c/55f1cbeaa15945e38bf892380966a9eb90f7734b