Skip to contentSkip to conversation

scripts/mksysmap: Ignore prefixed KCFI symbols

PATCH Superseded Pierre-Clément Tosi 3 participants 4 messages Jun 23, 2023 – Jun 26, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/mksysmap: Ignore prefixed KCFI symbols

The (relatively) new KCFI feature in LLVM/Clang encodes type information for C functions by generating symbols named __kcfi_typeid_<fname>, which can then be referenced from assembly. However, some custom build rules (e.g. EFI, nVHE, or early PIE on arm64) use objcopy to add a prefix to all the symbols in their object files, making mksysmap's ignore filter miss those KCFI symbols.

Therefore, explicitly list those twice-prefixed KCFI symbols as ignored.

Alternatively, this could also be achieved in a less verbose way by ignoring any symbol containing the string "__kcfi_typeid_". However, listing the combined prefixes explicitly saves us from running the small risk of ignoring symbols that should be kept.

---
 scripts/mksysmap | 3 +++
 1 file changed, 3 insertions(+)
scripts/mksysmap +3 -0
index 26f39772f7a5..17cf4292e26b 100755
@@ -61,7 +61,10 @@ ${NM} -n ${1} | sed >${2} -e "
 / __microLA25Thunk_/d
 
 # CFI type identifiers
+/ __efistub___kcfi_typeid_/d
 / __kcfi_typeid_/d
+/ __kvm_nvhe___kcfi_typeid_/d
+/ __pi___kcfi_typeid_/d
 
 # CRC from modversions
 / __crc_/d
Signature · 5 lines
2.41.0.162.gfafddb0af9-goog


-- 
Pierre
Reviewed-by on v1 1/1
#1 lore raw

Hi Pierre-Clément,

Quoted 25 lines · Pierre-Clément Tosi

The (relatively) new KCFI feature in LLVM/Clang encodes type information for C functions by generating symbols named __kcfi_typeid_<fname>, which can then be referenced from assembly. However, some custom build rules (e.g. EFI, nVHE, or early PIE on arm64) use objcopy to add a prefix to all the symbols in their object files, making mksysmap's ignore filter miss those KCFI symbols.

Therefore, explicitly list those twice-prefixed KCFI symbols as ignored.

Alternatively, this could also be achieved in a less verbose way by ignoring any symbol containing the string "__kcfi_typeid_". However, listing the combined prefixes explicitly saves us from running the small risk of ignoring symbols that should be kept.

---
 scripts/mksysmap | 3 +++
 1 file changed, 3 insertions(+)
scripts/mksysmap +0 -0
index 26f39772f7a5..17cf4292e26b 100755

scripts/mksysmap ${NM} -n ${1} | sed >${2} -e " · line 64

Quoted 4 lines
scripts/mksysmap +1 -0
@@ -61,7 +61,10 @@ ${NM} -n ${1} | sed >${2} -e "
 / __microLA25Thunk_/d
 
 # CFI type identifiers
+/ __efistub___kcfi_typeid_/d

Does the existing __efistub_/d rule not catch this?

scripts/mksysmap ${NM} -n ${1} | sed >${2} -e " · line 67

Quoted 3 lines
scripts/mksysmap +2 -0
 / __kcfi_typeid_/d
+/ __kvm_nvhe___kcfi_typeid_/d
+/ __pi___kcfi_typeid_/d

Either way, otherwise this looks reasonable to me. Thanks for the patch!

Sami

#2 lore raw
Quoted 31 lines · Sami Tolvanen

Hi Pierre-Clément,

Quoted 27 lines · Pierre-Clément Tosi

The (relatively) new KCFI feature in LLVM/Clang encodes type information for C functions by generating symbols named __kcfi_typeid_<fname>, which can then be referenced from assembly. However, some custom build rules (e.g. EFI, nVHE, or early PIE on arm64) use objcopy to add a prefix to all the symbols in their object files, making mksysmap's ignore filter miss those KCFI symbols.

Therefore, explicitly list those twice-prefixed KCFI symbols as ignored.

Alternatively, this could also be achieved in a less verbose way by ignoring any symbol containing the string "__kcfi_typeid_". However, listing the combined prefixes explicitly saves us from running the small risk of ignoring symbols that should be kept.

---
 scripts/mksysmap | 3 +++
 1 file changed, 3 insertions(+)
scripts/mksysmap +0 -0
index 26f39772f7a5..17cf4292e26b 100755
@@ -61,7 +61,10 @@ ${NM} -n ${1} | sed >${2} -e "
 / __microLA25Thunk_/d
 
Quoted 4 lines

scripts/mksysmap ${NM} -n ${1} | sed >${2} -e " · line 64

Quoted 2 lines
scripts/mksysmap +1 -0
 # CFI type identifiers
+/ __efistub___kcfi_typeid_/d

Does the existing __efistub_/d rule not catch this?

Agree with Sami.

This line looks redundant to me.

Quoted 10 lines

scripts/mksysmap ${NM} -n ${1} | sed >${2} -e " · line 67

Quoted 4 lines
scripts/mksysmap +2 -0
 / __kcfi_typeid_/d
+/ __kvm_nvhe___kcfi_typeid_/d
+/ __pi___kcfi_typeid_/d

Either way, otherwise this looks reasonable to me. Thanks for the patch!

Sami

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw

PATCH v2 1/1 scripts/mksysmap: Ignore prefixed KCFI symbols

In reply to Pierre-Clément Tosi

The (relatively) new KCFI feature in LLVM/Clang encodes type information for C functions by generating symbols named __kcfi_typeid_<fname>, which can then be referenced from assembly. However, some custom build rules (e.g. nVHE or early PIE on arm64) use objcopy to add a prefix to all the symbols in their object files, making mksysmap's ignore filter miss those KCFI symbols.

Therefore, explicitly list those twice-prefixed KCFI symbols as ignored.

Alternatively, this could also be achieved in a less verbose way by ignoring any symbol containing the string "__kcfi_typeid_". However, listing the combined prefixes explicitly saves us from running the small risk of ignoring symbols that should be kept.

---
Changes in v2:
Removed redundant filter for EFI KCFI symbol names.

 scripts/mksysmap | 2 ++
 1 file changed, 2 insertions(+)
scripts/mksysmap +2 -0
index 26f39772f7a5..9ba1c9da0a40 100755
@@ -62,6 +62,8 @@ ${NM} -n ${1} | sed >${2} -e "
 
 # CFI type identifiers
 / __kcfi_typeid_/d
+/ __kvm_nvhe___kcfi_typeid_/d
+/ __pi___kcfi_typeid_/d
 
 # CRC from modversions
 / __crc_/d
Signature · 5 lines
2.41.0.162.gfafddb0af9-goog


-- 
Pierre