History

kbuild: do not create *.prelink.o for Clang LTO or IBT

When CONFIG_LTO_CLANG=y, additional intermediate *.prelink.o is created for each module. Also, objtool is postponed until LLVM IR is converted to ELF. CONFIG_X86_KERNEL_IBT works in a similar way to postpone objtool until objects are merged together. This commit stops generating *.prelink.o, so the build flow will look similar with/without LTO. The following figures show how the LTO build currently works, and how this commit is changing it. Current build flow ================== [1] single-object module $(LD) $(CC) +objtool $(LD) foo.c --------------------> foo.o -----> foo.prelink.o -----> foo.ko (LLVM IR) (ELF) | (ELF) | foo.mod.o --/ (LLVM IR) [2] multi-object module $(LD) $(CC) $(AR) +objtool $(LD) foo1.c -----> foo1.o -----> foo.o -----> foo.prelink.o -----> foo.ko | (archive) (ELF) | (ELF) foo2.c -----> foo2.o --/ | (LLVM IR) foo.mod.o --/ (LLVM IR) One confusion is that foo.o in multi-object module is an archive despite of its suffix. New build flow ============== [1] single-object module Since there is only one object, there is no need to keep the LLVM IR. Use $(CC)+$(LD) to generate an ELF object in one build rule. When LTO is disabled, $(LD) is unneeded because $(CC) produces an ELF object. $(CC)+$(LD)+objtool $(LD) foo.c ----------------------------> foo.o ---------> foo.ko (ELF) | (ELF) | foo.mod.o --/ (LLVM IR) [2] multi-object module Previously, $(AR) was used to combine LLVM IR files into an archive, but there was no technical reason to do so. Use $(LD) to merge them into a single ELF object. $(LD) $(CC) +objtool $(LD) foo1.c ---------> foo1.o ---------> foo.o ---------> foo.ko | (ELF) | (ELF) foo2.c ---------> foo2.o ----/ | (LLVM IR) foo.mod.o --/ (LLVM IR)

Masahiro Yamada committed 4 years ago

Commit c25e1c51 parent 0cfd9006 files · +28 −67Browse files

Showing the changes to scripts/mod (1 of 6 files). Show all

Unified · Split

scripts/mod/modpost.c+0−7
@@ -1903,10 +1903,6 @@ static char *remove_dot(char *s) · 1902 unmodified lines
19031903 size_t m = strspn(s + n + 1, "0123456789");
19041904 if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0))
19051905 s[n] = 0;
1906−
1907− /* strip trailing .prelink */
1908− if (strends(s, ".prelink"))
1909− s[strlen(s) - 8] = '\0';
19101906 }
19111907 return s;
19121908 }
@@ -2028,9 +2024,6 @@ static void read_symbols(const char *modname) · 115 unmodified lines
20282024 /* strip trailing .o */
20292025 tmp = NOFAIL(strdup(modname));
20302026 tmp[strlen(tmp) - 2] = '\0';
2031− /* strip trailing .prelink */
2032− if (strends(tmp, ".prelink"))
2033− tmp[strlen(tmp) - 8] = '\0';
20342027 mod = new_module(tmp);
20352028 free(tmp);
20362029 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t