Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run clang with original optimizer, which is needed to verify Linux kernel #1781

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

master-q
Copy link

Infer used -O0 option to build AST and foo.o file. But on Linux kernel, the source code is written to be used -O2 optimizer level. We had failure on verifing Linux kernel code with Infer as following:

$ infer -- make CC=clang -j`nproc`
--snip--
  LD      vmlinux.o
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
  MODPOST Module.symvers
WARNING: modpost: vmlinux.o: section mismatch in reference: startup_64_load_idt (section: .text) -> vc_no_ghcb (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: pgtable_init (section: .text) -> pgtable_cache_init (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: real_mode_size_needed (section: .text) -> real_mode_blob (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: real_mode_size_needed (section: .text) -> real_mode_blob_end (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: find_smp_config (section: .text) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: get_smp_config (section: .text) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: __get_mem_config_intel (section: .text) -> thread_throttle_mode_init (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: __set_percpu_decrypted (section: .text) -> early_set_memory_decrypted (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: early_get_smp_config (section: .text) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: real_mode_size_needed (section: .text) -> real_mode_blob (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: real_mode_size_needed (section: .text) -> real_mode_blob_end (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: memblock_alloc_low (section: .text) -> memblock_alloc_try_nid (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: memblock_alloc_from (section: .text) -> memblock_alloc_try_nid (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: memblock_alloc_raw (section: .text) -> memblock_alloc_try_nid_raw (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: memblock_alloc_node (section: .text) -> memblock_alloc_try_nid (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: acpi_arch_set_root_pointer (section: .text) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: acpi_arch_get_root_pointer (section: .text) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: acpi_sleep_suspend_setup (section: .text) -> acpi_s2idle_setup (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: dmar_fault.rs (section: .data) -> dmar_parse_one_rmrr (section: .init.text)
WARNING: modpost: vmlinux.o: section mismatch in reference: dmar_fault.rs (section: .data) -> dmar_parse_one_andd (section: .init.text)
WARNING: modpost: arch/x86/kvm/kvm-amd.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
WARNING: modpost: arch/x86/kvm/kvm-amd.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
WARNING: modpost: arch/x86/kvm/kvm-amd.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
WARNING: modpost: drivers/platform/x86/thinkpad_acpi.o: section mismatch in reference: volume_set_software_mute (section: .text) -> tpacpi_is_lenovo (section: .init.text)
ERROR: modpost: "kvm_xen_update_runstate_guest" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "kvm_xen_hypercall" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "__ubifs_hash_get_desc" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "ubifs_bad_hash" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "__ubifs_node_calc_hash" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "__ubifs_node_verify_hmac" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "ubifs_hmac_wkm" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "ubifs_prepare_auth_node" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "__ubifs_exit_authentication" [fs/ubifs/ubifs.ko] undefined!
ERROR: modpost: "__ubifs_node_insert_hmac" [fs/ubifs/ubifs.ko] undefined!
WARNING: modpost: suppressed 9 unresolved symbol warnings because there were too many)
make[1]: *** [scripts/Makefile.modpost:126: Module.symvers] Error 1

Infer can verify Linux kernel code with this patch and some patches for kernel as following:

https://gist.github.com/master-q/4b3e09e664a15187290f0f22d1bcb3c6

@master-q master-q changed the title Run clang with original optimizer Run clang with original optimizer, which is needed to verify Linux kernel Jul 16, 2023
@jvillard
Copy link
Contributor

jvillard commented Apr 2, 2024

Thanks for the report and the patches! This will run clang twice on every file that infer analyses, which could be expensive. Would it be ok to gate this behind an option like --also-run-original-compilation-command?

@master-q
Copy link
Author

master-q commented Apr 2, 2024

Yes. It's a good idea!

@master-q master-q force-pushed the feature/run-clang-original-optimizer branch from 80e8b4b to c997407 Compare April 4, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants