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

-finstrument-functions linking error on Apple clang #7895

Open
paranlee opened this issue Dec 17, 2023 · 0 comments
Open

-finstrument-functions linking error on Apple clang #7895

paranlee opened this issue Dec 17, 2023 · 0 comments

Comments

@paranlee
Copy link

We want to solve the -finstrument-functions linking error.
Even If When we do -finstrument-functions compiler option on basic hello world program. :)

clang -O0 -ggdb -finstrument-functions -v main.c -o HelloMac

ld: Undefined symbols:
  ___cyg_profile_func_enter, referenced from:
      _func2 in main-7eb0ac.o
      _func1 in main-7eb0ac.o
      _main in main-7eb0ac.o
  ___cyg_profile_func_exit, referenced from:
      _func2 in main-7eb0ac.o
      _func1 in main-7eb0ac.o
      _main in main-7eb0ac.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...

This issue emerged from some PoC on uftrace project.

$ uname -a

Darwin gimyunscBookAir 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112 arm64
gimyunscBookAir:HelloMac yunseong$ clang -v
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
gimyunscBookAir:HelloMac yunseong$ history | grep ktrace
  488  sudo ktrace trace -S -f C3 -c clang -O0 -ggdb -finstrument-functions -v main.c -o HelloMac
  616  history | grep ktrace
$ sudo ktrace trace -S -f C3 -c clang -O0 -ggdb -finstrument-functions -v main.c -o HelloMac

Launching 'clang -O0 -ggdb -finstrument-functions -v main.c -o HelloMac'
walltime                          delta(us)(duration)    debug-id                             arg1             arg2             arg3             arg4             thread-id        cpu  process-name(pid)                             

Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple arm64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-strict-return -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fobjc-msgsend-selector-stubs -target-sdk-version=14.2 -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +crc -target-feature +lse -target-feature +rdm -target-feature +crypto -target-feature +dotprod -target-feature +fp-armv8 -target-feature +neon -target-feature +fp16fml -target-feature +ras -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -target-linker-version 1022.1 -v -finstrument-functions -fcoverage-compilation-dir=/Users/yunseong/Desktop/cpp-project/HelloMac/HelloMac -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -O0 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -fdebug-compilation-dir=/Users/yunseong/Desktop/cpp-project/HelloMac/HelloMac -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/main-7eb0ac.o -x c main.c
clang -cc1 version 15.0.0 (clang-1500.1.0.2.5) default target arm64-apple-darwin23.2.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 14.0.0 14.2 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -O0 -o HelloMac -L/usr/local/lib /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/main-7eb0ac.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.osx.a
ld: Undefined symbols:
  ___cyg_profile_func_enter, referenced from:
      _func2 in main-7eb0ac.o
      _func1 in main-7eb0ac.o
      _main in main-7eb0ac.o
  ___cyg_profile_func_exit, referenced from:
      _func2 in main-7eb0ac.o
      _func1 in main-7eb0ac.o
      _main in main-7eb0ac.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...

There are the log message by the ktrace. I want to see the library we are looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant