Is that true that Go dynamic linked to libc in Linux and Mac is different? I am trying to evaluate the use of LD_PRELOAD (Linux) or DYLD_INSERT_LIBRARIES (macOS) to intercept the bind (listen) function. It's working on macOS but not on Linux.
On macOS:
❯ otool -tV main | grep bind
_x_cgo_bindm:
0000000100090134 bl _syscall.bind
_syscall.bind:
0000000100090578 b _syscall.bind
_syscall.libc_bind_trampoline.abi0:
On Linux:
# objdump -T ./main
./main: file format elf64-x86-64
DYNAMIC SYMBOL TABLE:
0000000000545a80 g DF .text 0000000000000063 Base crosscall2
0000000000545a40 g DF .text 0000000000000037 Base _cgo_panic
0000000000466ae0 g DF .text 0000000000000019 Base _cgo_topofstack
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) __errno_location
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) getaddrinfo
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) free
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) freeaddrinfo
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) gai_strerror
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) stderr
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) fwrite
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) vfprintf
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) fputc
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) abort
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) pthread_mutex_lock
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.3.2) pthread_cond_wait
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) pthread_mutex_unlock
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.3.2) pthread_cond_broadcast
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.34) pthread_create
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) nanosleep
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.34) pthread_detach
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) strerror
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) fprintf
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) malloc
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) pthread_attr_init
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.34) pthread_attr_getstacksize
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) pthread_attr_destroy
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) sigfillset
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.32) pthread_sigmask
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) mmap
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) munmap
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) setenv
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) unsetenv
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) sigemptyset
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) sigaddset
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) sigaction
0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) sigismember
Is there anyway to force Go binary in Linux use bind/connect function as macOS?