Skip to content

Shim wishlist #2057

Open
Open
@saethlin

Description

@saethlin

I run Miri on the most-downloaded crates, with the flags -Zmiri-panic-on-unsupported and --no-fail-fast which basically asks Miri to try to run as many tests as it can. Searching all my build logs, I find these are the most-encountered can't call foreign function: errors:

117310 counts
(  1)    16419 (14.0%, 14.0%): socket
(  2)     7934 ( 6.8%, 20.8%): TLS_method
(  3)     5867 ( 5.0%, 25.8%): getaddrinfo
(  4)     3964 ( 3.4%, 29.1%): OPENSSL_init_ssl
(  5)     3172 ( 2.7%, 31.8%): fchmod
(  6)     2957 ( 2.5%, 34.4%): ring_core_0_17_8_OPENSSL_cpuid_setup
(  7)     2485 ( 2.1%, 36.5%): rust_psm_stack_pointer
(  8)     2432 ( 2.1%, 38.6%): rocksdb_options_create
(  9)     2167 ( 1.8%, 40.4%): getrlimit
( 10)     1880 ( 1.6%, 42.0%): dlopen
( 11)     1875 ( 1.6%, 43.6%): ts_parser_new
( 12)     1800 ( 1.5%, 45.1%): sodium_init
( 13)     1798 ( 1.5%, 46.7%): Py_IsInitialized
( 14)     1619 ( 1.4%, 48.1%): sqlite3_open_v2
( 15)     1415 ( 1.2%, 49.3%): epoll_create
( 16)     1382 ( 1.2%, 50.4%): sqlite3_threadsafe
( 17)     1365 ( 1.2%, 51.6%): GFp_cpuid_setup
( 18)     1293 ( 1.1%, 52.7%): chmod
( 19)     1155 ( 1.0%, 53.7%): SQLAllocHandle
( 20)     1003 ( 0.9%, 54.5%): geteuid
( 21)      745 ( 0.6%, 55.2%): rustsecp256k1_v0_10_0_context_preallocated_size
( 22)      713 ( 0.6%, 55.8%): InitializeMagick
( 23)      699 ( 0.6%, 56.4%): EVP_sha256
( 24)      694 ( 0.6%, 57.0%): ruby_init_stack
( 25)      629 ( 0.5%, 57.5%): access
( 26)      604 ( 0.5%, 58.0%): JS_NewRuntime
( 27)      600 ( 0.5%, 58.5%): PQconnectdb
( 28)      549 ( 0.5%, 59.0%): ioctl
( 29)      527 ( 0.4%, 59.5%): blst_scalar_from_uint64
( 30)      526 ( 0.4%, 59.9%): v8__Platform__NewDefaultPlatform
( 31)      520 ( 0.4%, 60.3%): __bid128_from_string
( 32)      516 ( 0.4%, 60.8%): nettle_yarrow256_init
( 33)      485 ( 0.4%, 61.2%): mdb_env_create
( 34)      482 ( 0.4%, 61.6%): NK_login_enum
( 35)      479 ( 0.4%, 62.0%): mprotect
( 36)      476 ( 0.4%, 62.4%): tree_sitter_tsx
( 37)      474 ( 0.4%, 62.8%): LLVMCreateMemoryBufferWithContentsOfFile
( 38)      440 ( 0.4%, 63.2%): git_libgit2_init
( 39)      426 ( 0.4%, 63.6%): roaring_bitmap_init_with_capacity
( 40)      407 ( 0.3%, 63.9%): getifaddrs
( 41)      380 ( 0.3%, 64.2%): blst_keygen_v4_5
( 42)      380 ( 0.3%, 64.6%): secp256k1_context_create
( 43)      367 ( 0.3%, 64.9%): decContextDefault
( 44)      367 ( 0.3%, 65.2%): ffopen
( 45)      342 ( 0.3%, 65.5%): SQLSetEnvAttr
( 46)      338 ( 0.3%, 65.8%): sigaction
( 47)      334 ( 0.3%, 66.0%): H5dont_atexit
( 48)      320 ( 0.3%, 66.3%): mrb_open
( 49)      312 ( 0.3%, 66.6%): cuInit

There are some pretty obvious biases in this data. For example, crates with a lot of tests get their favorite symbols counted more than crates with fewer tests.

There are also a lot of things in here which I don't think we will ever support via shims. We're not going to have shims for openssl. We're also not going to shim CUDA or JavaScript, and also all those errors are from 3 crates using CUDA and 1 crate doing some JavaScript thing.

But in any case, this is a starting point for prioritizing what shims should be added. Just in case there isn't anyone out there who already has a pet function they want added.

@drmeepster asked me to run some crates with a Windows target. Here's what the first ~2k crates run into:

2911 counts
(  1)     1583 (54.4%, 54.4%):  GetFullPathNameW
(  2)      485 (16.7%, 71.0%):  CreateIoCompletionPort
(  3)      292 (10.0%, 81.1%):  GetFileInformationByHandleEx
(  4)      183 ( 6.3%, 87.4%):  GetModuleFileNameW
(  5)       46 ( 1.6%, 88.9%):  SleepConditionVariableSRW
(  6)       24 ( 0.8%, 89.8%):  GetTickCount64
(  7)       22 ( 0.8%, 90.5%):  CompareStringOrdinal
(  8)       18 ( 0.6%, 91.1%):  AcquireCredentialsHandleA
(  9)       16 ( 0.5%, 91.7%):  WSAStartup
( 10)       15 ( 0.5%, 92.2%):  CreateNamedPipeW
( 11)       14 ( 0.5%, 92.7%):  Sleep
( 12)       13 ( 0.4%, 93.1%):  CryptAcquireContextW
( 13)       13 ( 0.4%, 93.6%):  log1p
( 14)       11 ( 0.4%, 94.0%):  CreateSemaphoreA
( 15)       10 ( 0.3%, 94.3%):  CreatePipe
( 16)       10 ( 0.3%, 94.6%):  SHGetKnownFolderPath
( 17)       10 ( 0.3%, 95.0%):  WakeAllConditionVariable
( 18)       10 ( 0.3%, 95.3%):  zx_vmo_create
( 19)        8 ( 0.3%, 95.6%):  GetCurrentProcess

I don't know what GetFullPathNameW is coming from, but when crates hit it, they usually have tends to hundreds of tests that attempt to use it. Possibly it's from proptest? prost is one of the crates that hits it a bunch of times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-shimsArea: This affects the external function shimsC-proposalCategory: a proposal for something we might want to do, or maybe not; details still being worked out

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions