Skip to content

add tests which assert that import list for simple executable not changed silently #121494

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/run-make/assert_imports_windows-msvc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# only-x86_64-pc-windows-msvc

include ../tools.mk

# assert that import list for simple executable not changed silently
# FIXME: remove "File:" from diff by making path reproducible: now it's broken

all:
$(RUSTC) empty.rs
"$(LLVM_BIN_DIR)"/llvm-readobj --coff-imports $(TMPDIR)/empty.exe > "$(TMPDIR)/actual.empty.txt"
diff -u -I "File:" -I "ImportLookupTableRVA:" -I "ImportAddressTableRVA:" expected.empty.txt "$(TMPDIR)/actual.empty.txt"
1 change: 1 addition & 0 deletions tests/run-make/assert_imports_windows-msvc/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
122 changes: 122 additions & 0 deletions tests/run-make/assert_imports_windows-msvc/expected.empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

File: empty.exe
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Import {
Name: KERNEL32.dll
ImportLookupTableRVA: 0x207C0
ImportAddressTableRVA: 0x19000
Symbol: GetLastError (619)
Symbol: AddVectoredExceptionHandler (19)
Symbol: SetThreadStackGuarantee (1408)
Symbol: WaitForSingleObject (1528)
Symbol: QueryPerformanceCounter (1115)
Symbol: AcquireSRWLockExclusive (0)
Symbol: RtlCaptureContext (1247)
Symbol: RtlVirtualUnwind (1262)
Symbol: RtlLookupFunctionEntry (1255)
Symbol: SetLastError (1357)
Symbol: GetCurrentDirectoryW (539)
Symbol: GetEnvironmentVariableW (580)
Symbol: GetCurrentProcess (545)
Symbol: GetStdHandle (737)
Symbol: GetCurrentProcessId (546)
Symbol: TryAcquireSRWLockExclusive (1477)
Symbol: HeapFree (862)
Symbol: HeapReAlloc (865)
Symbol: AcquireSRWLockShared (1)
Symbol: ReleaseSRWLockShared (1219)
Symbol: ReleaseMutex (1216)
Symbol: GetModuleHandleA (639)
Symbol: GetProcAddress (700)
Symbol: GetProcessHeap (707)
Symbol: GetConsoleMode (518)
Symbol: GetModuleHandleW (642)
Symbol: MultiByteToWideChar (1023)
Symbol: WriteConsoleW (1586)
Symbol: GetCurrentThread (549)
Symbol: GetSystemTimeAsFileTime (760)
Symbol: WaitForSingleObjectEx (1529)
Symbol: LoadLibraryA (977)
Symbol: CreateMutexA (218)
Symbol: ReleaseSRWLockExclusive (1218)
Symbol: HeapAlloc (858)
Symbol: CloseHandle (137)
Symbol: SetUnhandledExceptionFilter (1421)
Symbol: UnhandledExceptionFilter (1486)
Symbol: IsDebuggerPresent (910)
Symbol: InitializeSListHead (888)
Symbol: GetCurrentThreadId (550)
Symbol: IsProcessorFeaturePresent (917)
}
Import {
Name: ntdll.dll
ImportLookupTableRVA: 0x20A50
ImportAddressTableRVA: 0x19290
Symbol: RtlNtStatusToDosError (1294)
Symbol: NtWriteFile (665)
}
Import {
Name: VCRUNTIME140.dll
ImportLookupTableRVA: 0x20918
ImportAddressTableRVA: 0x19158
Symbol: __current_exception_context (28)
Symbol: __current_exception (27)
Symbol: __C_specific_handler (8)
Symbol: _CxxThrowException (1)
Symbol: memcmp (59)
Symbol: memmove (61)
Symbol: memset (62)
Symbol: memcpy (60)
Symbol: __CxxFrameHandler3 (14)
}
Import {
Name: api-ms-win-crt-runtime-l1-1-0.dll
ImportLookupTableRVA: 0x209A0
ImportAddressTableRVA: 0x191E0
Symbol: _initterm_e (55)
Symbol: exit (85)
Symbol: _exit (35)
Symbol: _initterm (54)
Symbol: _get_initial_narrow_environment (40)
Symbol: __p___argc (4)
Symbol: __p___argv (5)
Symbol: _cexit (22)
Symbol: _c_exit (21)
Symbol: _register_thread_local_exe_atexit_callback (61)
Symbol: _configure_narrow_argv (24)
Symbol: _set_app_type (66)
Symbol: _initialize_narrow_environment (51)
Symbol: _initialize_onexit_table (52)
Symbol: _register_onexit_function (60)
Symbol: _crt_atexit (30)
Symbol: terminate (103)
Symbol: _seh_filter_exe (64)
}
Import {
Name: api-ms-win-crt-math-l1-1-0.dll
ImportLookupTableRVA: 0x20990
ImportAddressTableRVA: 0x191D0
Symbol: __setusermatherr (9)
}
Import {
Name: api-ms-win-crt-stdio-l1-1-0.dll
ImportLookupTableRVA: 0x20A38
ImportAddressTableRVA: 0x19278
Symbol: _set_fmode (84)
Symbol: __p__commode (1)
}
Import {
Name: api-ms-win-crt-locale-l1-1-0.dll
ImportLookupTableRVA: 0x20980
ImportAddressTableRVA: 0x191C0
Symbol: _configthreadlocale (8)
}
Import {
Name: api-ms-win-crt-heap-l1-1-0.dll
ImportLookupTableRVA: 0x20968
ImportAddressTableRVA: 0x191A8
Symbol: free (24)
Symbol: _set_new_mode (22)
}
11 changes: 11 additions & 0 deletions tests/run-make/assert_imports_x86_64-unknown-linux-gnu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# only-x86_64-unknown-linux-gnu

include ../tools.mk

# assert that import list for simple executable not changed silently
# requires binutils

all:
$(RUSTC) empty.rs
readelf --dyn-syms -W $(TMPDIR)/empty > "$(TMPDIR)/actual.empty.txt"
diff -u expected.empty.txt "$(TMPDIR)/actual.empty.txt"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

Symbol table '.dynsym' contains 65 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getenv@GLIBC_2.2.5 (2)
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND dl_iterate_phdr@GLIBC_2.2.5 (2)
3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND free@GLIBC_2.2.5 (2)
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.34 (3)
5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.2.5 (2)
6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_Backtrace@GCC_3.3 (4)
7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __errno_location@GLIBC_2.2.5 (2)
8: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND writev@GLIBC_2.2.5 (2)
10: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_getattr_np@GLIBC_2.32 (5)
11: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sigaction@GLIBC_2.2.5 (2)
12: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_thread_atexit_impl@GLIBC_2.18 (6)
13: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __xpg_strerror_r@GLIBC_2.3.4 (7)
14: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_getspecific@GLIBC_2.34 (3)
15: 0000000000000000 0 FUNC GLOBAL DEFAULT UND readlink@GLIBC_2.2.5 (2)
16: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fcntl@GLIBC_2.2.5 (2)
17: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetRegionStart@GCC_3.0 (8)
18: 0000000000000000 0 FUNC GLOBAL DEFAULT UND write@GLIBC_2.2.5 (2)
19: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetTextRelBase@GCC_3.0 (8)
20: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_RaiseException@GCC_3.0 (8)
21: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strlen@GLIBC_2.2.5 (2)
22: 0000000000000000 0 FUNC GLOBAL DEFAULT UND stat64@GLIBC_2.33 (9)
23: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_create@GLIBC_2.34 (3)
24: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memset@GLIBC_2.2.5 (2)
25: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getcwd@GLIBC_2.2.5 (2)
26: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetIPInfo@GCC_4.2.0 (10)
27: 0000000000000000 0 FUNC GLOBAL DEFAULT UND close@GLIBC_2.2.5 (2)
28: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetLanguageSpecificData@GCC_3.0 (8)
29: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_key_delete@GLIBC_2.34 (3)
30: 0000000000000000 0 FUNC GLOBAL DEFAULT UND read@GLIBC_2.2.5 (2)
31: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __tls_get_addr@GLIBC_2.3 (11)
32: 0000000000000000 0 FUNC GLOBAL DEFAULT UND calloc@GLIBC_2.2.5 (2)
33: 0000000000000000 0 FUNC GLOBAL DEFAULT UND signal@GLIBC_2.2.5 (2)
34: 0000000000000000 0 FUNC GLOBAL DEFAULT UND syscall@GLIBC_2.2.5 (2)
35: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_getstack@GLIBC_2.34 (3)
36: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
37: 0000000000000000 0 FUNC GLOBAL DEFAULT UND realpath@GLIBC_2.3 (12)
38: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.14 (13)
39: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetIP@GCC_3.0 (8)
40: 0000000000000000 0 FUNC GLOBAL DEFAULT UND mmap64@GLIBC_2.2.5 (2)
41: 0000000000000000 0 FUNC GLOBAL DEFAULT UND malloc@GLIBC_2.2.5 (2)
42: 0000000000000000 0 FUNC GLOBAL DEFAULT UND bcmp@GLIBC_2.2.5 (2)
43: 0000000000000000 0 FUNC GLOBAL DEFAULT UND realloc@GLIBC_2.2.5 (2)
44: 0000000000000000 0 FUNC GLOBAL DEFAULT UND munmap@GLIBC_2.2.5 (2)
45: 0000000000000000 0 FUNC WEAK DEFAULT UND statx@GLIBC_2.28 (14)
46: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_GetDataRelBase@GCC_3.0 (8)
47: 0000000000000000 0 FUNC GLOBAL DEFAULT UND poll@GLIBC_2.2.5 (2)
48: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_SetGR@GCC_3.0 (8)
49: 0000000000000000 0 FUNC GLOBAL DEFAULT UND open64@GLIBC_2.2.5 (2)
50: 0000000000000000 0 FUNC GLOBAL DEFAULT UND memmove@GLIBC_2.2.5 (2)
51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_self@GLIBC_2.2.5 (2)
52: 0000000000000000 0 FUNC GLOBAL DEFAULT UND mprotect@GLIBC_2.2.5 (2)
53: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sysconf@GLIBC_2.2.5 (2)
54: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_attr_destroy@GLIBC_2.2.5 (2)
55: 0000000000000000 0 FUNC GLOBAL DEFAULT UND lseek64@GLIBC_2.2.5 (2)
56: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fstat64@GLIBC_2.33 (9)
57: 0000000000000000 0 FUNC GLOBAL DEFAULT UND posix_memalign@GLIBC_2.2.5 (2)
58: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
59: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_DeleteException@GCC_3.0 (8)
60: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sigaltstack@GLIBC_2.2.5 (2)
61: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_Resume@GCC_3.0 (8)
62: 0000000000000000 0 FUNC GLOBAL DEFAULT UND pthread_setspecific@GLIBC_2.34 (3)
63: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _Unwind_SetIP@GCC_3.0 (8)
64: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2)