ClangBuiltLinux/linux

Segmentation fault in modpost when building UML on mainline after LLVM commit 4bf8a688956a

Closed this issue · 8 comments

After llvm/llvm-project@4bf8a68 (according to my bisect), I see a segmentation fault in modpost when building UML on mainline (ARCH=um has -mcmodel=large as a result of 12783aa):

$ make -kj"$(nproc)" ARCH=um LLVM=1 mrproper defconfig linux
...
  AR      vmlinux.a
  LD      vmlinux.o
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
  MODPOST vmlinux.symvers
make[4]: *** [scripts/Makefile.modpost:145: vmlinux.symvers] Error 139
...
git bisect log
# bad: [f1156fb622a73bcf1623c9bebfb6a638b097af14] [AMDGPU][IGLP]: Add SchedGroupMask::TRANS (#75416)
# good: [065796bb9293b222fa3d63311af542a98b96d09a] [clang][OpenMP] Fix missing DI for __kmpc_global_thread_num (#73856)
git bisect start 'f1156fb622a73bcf1623c9bebfb6a638b097af14' '065796bb9293b222fa3d63311af542a98b96d09a'
# bad: [774295ca1d5ff752cb478b61f22a5b1dbe33074f] [libc++][test] Fix MSVC warnings with `static_cast`s (#74962)
git bisect bad 774295ca1d5ff752cb478b61f22a5b1dbe33074f
# bad: [34cdc913214fd9561b6ec8d535bd3d0313772cb5] [NFC][DebugInfo][RemoveDIs] Use iterators to insert in callsite-splitting (#74455)
git bisect bad 34cdc913214fd9561b6ec8d535bd3d0313772cb5
# bad: [bdcf2087d9fb6112cc5a367590a633796af83015] Recommit "[InstCombine] Retain exact instruction name for some cases in SimplifyDemandedUseBits."
git bisect bad bdcf2087d9fb6112cc5a367590a633796af83015
# bad: [93636581d3589b3b986c0080a82de7fc0bbd01cf] [InstCombiner] Make isFreeToInvert() and friends instance functions (NFC)
git bisect bad 93636581d3589b3b986c0080a82de7fc0bbd01cf
# bad: [985c0d1903c173b896674b30480992e2414b8aa0] [libc][mincore] use correct page_size for test (#73984)
git bisect bad 985c0d1903c173b896674b30480992e2414b8aa0
# good: [fce4c0acd6db4bd8598db7eb471ccca60dc05406] [OpenMP] Start organizing PluginManager, PluginAdaptors (#73875)
git bisect good fce4c0acd6db4bd8598db7eb471ccca60dc05406
# good: [87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d] Allow for mixing source/no-source DIFiles in one CU
git bisect good 87e22bdd2bd6d77d782f9d64b3e3ae5bdcd5080d
# bad: [1035cc7029180243de371384eee91f4e1e87d199] [OpenMP][NFC] Encapsulate Devices.size() (#74010)
git bisect bad 1035cc7029180243de371384eee91f4e1e87d199
# bad: [3dbac2c007c114a720300d2a4d79abe9ca1351e7] [mlir] Expose type and attribute names in the MLIRContext and abstract type/attr classes (#72189)
git bisect bad 3dbac2c007c114a720300d2a4d79abe9ca1351e7
# bad: [148dec9fa43b3a16b08169df8bdf3bbae24aa9b0] [OpenMP][NFC] Separate Envar (environment variable) handling (#73994)
git bisect bad 148dec9fa43b3a16b08169df8bdf3bbae24aa9b0
# bad: [4bf8a688956a759b7b6b8d94f42d25c13c7af130] Reland [X86] With large code model, put functions into .ltext with large section flag (#73037)
git bisect bad 4bf8a688956a759b7b6b8d94f42d25c13c7af130
# first bad commit: [4bf8a688956a759b7b6b8d94f42d25c13c7af130] Reland [X86] With large code model, put functions into .ltext with large section flag (#73037)

After llvm/llvm-project@4bf8a68 (according to my bisect)

Perhaps related to the .ltext section somehow. cc @aeubanks

#1982 and this seem related.

This diff appears to resolve this issue for me:

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index cb6406f485a9..f7c4d3fe4381 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -807,7 +807,8 @@ static void check_section(const char *modname, struct elf_info *elf,

 #define DATA_SECTIONS ".data", ".data.rel"
 #define TEXT_SECTIONS ".text", ".text.*", ".sched.text", \
-               ".kprobes.text", ".cpuidle.text", ".noinstr.text"
+               ".kprobes.text", ".cpuidle.text", ".noinstr.text", \
+               ".ltext", ".ltext.*"
 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
                ".fixup", ".entry.text", ".exception.text", \
                ".coldtext", ".softirqentry.text"

However, I hit a very similar error to #1982:

  AR      built-in.a
  AR      vmlinux.a
  LD      vmlinux.o
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
  MODPOST vmlinux.symvers
  CC      .vmlinux.export.o
  UPD     include/generated/utsversion.h
  CC      init/version-timestamp.o
  LD      .tmp_vmlinux.kallsyms1
/usr/sbin/ld: init/main.o: relocation R_X86_64_32 against symbol `saved_command_line' can not be used when making a PIE object; recompile with -fPIE
/usr/sbin/ld: failed to set dynamic section sizes: bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [/home/nathan/cbl/src/linux/scripts/Makefile.vmlinux:37: vmlinux] Error 1

I think I have a fix for that issue, I will comment there.

(also, it's perhaps worth fixing modpost to not crash when a new section appears in the binary, regardless of the issues in this thread)

(also, it's perhaps worth fixing modpost to not crash when a new section appears in the binary, regardless of the issues in this thread)

Not sure it is section related, I bisected the crash down to https://git.kernel.org/linus/a23e7584ecf33df2b27ac176185c7b030ab0736f.

Regardless, I sent https://lore.kernel.org/20240123-fix-uml-clang-18-v1-2-efc095519cf9@kernel.org/ for this.

https://git.kernel.org/linus/a23e7584ecf33df2b27ac176185c7b030ab0736f

Speculation: There could be a bug in that commit; if is_executable_section really needed the original value of sym, the that commit uses the new value after find_tosym which is maybe wrong.

image
(what is that, a meme for ants?)

Merged into mainline: https://git.kernel.org/linus/397586506c3da005b9333ce5947ad01e8018a3be

This patch has Cc: stable@vger.kernel.org on it, so it will be backported automatically in time.