GithubHelp home page GithubHelp logo

mgehre / xunused Goto Github PK

View Code? Open in Web Editor NEW
50.0 50.0 12.0 24 KB

xunused is a tool to find unused C/C++ functions and methods across source files in the whole project.

License: Apache License 2.0

CMake 24.39% C++ 70.77% Dockerfile 4.84%

xunused's People

Contributors

bahnwaerter avatar hummer12007 avatar mgehre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xunused's Issues

Support for Weak functions

Thanks for making this tool, it's been really helpful finding some dead code for us!

We have a lot of __attribute__((weak)) functions for test tracing and whatnot, is it possible to recognize these cases? I'm suspecting not since weak overrides happen during linkage but I'm not familiar enough with Clang's tooling to understand if it can figure that out.

Example that xunused thought was unused:

// main.c
void __attribute__((weak)) foo(void) {
}

int main(void) {
    foo();
}


// test_wrap.c

// This one was found to be "unused"
void foo(void) {
    // Does actual stuff
}

Add compatibility with clang 9 and clang 10

Clang is updated quite a lot.
It would be nice to support latest version (10).

Also, I don't think it's worth to have several versions if it's hard to maintain, so support of version 9 (and 8) is under question.

Does clang need to be built in a special way?

I downloaded the clang-8.0.0 binary distribution for Mac OS X and attempted to build, but it seems to complain about missing typeinfo in llvm:

/Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/xunused.dir/link.txt --verbose=1
/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/bin/clang++ -std=c++17 -isysroot /Applications/Xcode_10.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/xunused.dir/main.cpp.o -o xunused -L/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib -Wl,-rpath,/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib -lclangIndex -lclangTooling -lclangFrontend -lclangDriver -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangASTMatchers -lclangAST -lclangEdit -lclangLex -lclangBasic /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86AsmParser.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMSupport.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMOption.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMProfileData.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Desc.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86AsmPrinter.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Utils.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMCDisassembler.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMObject.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMCParser.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMC.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDebugInfoCodeView.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDebugInfoMSF.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMBitReader.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Info.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMCore.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMBinaryFormat.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMSupport.a -lz -lcurses -lm /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDemangle.a
Undefined symbols for architecture x86_64:
"typeinfo for llvm::ErrorInfoBase", referenced from:
typeinfo for llvm::ErrorInfo<llvm::ErrorList, llvm::ErrorInfoBase> in main.cpp.o
"typeinfo for clang::ASTConsumer", referenced from:
typeinfo for XUnusedASTConsumer in main.cpp.o
"typeinfo for clang::ast_matchers::MatchFinder::MatchCallback", referenced from:
typeinfo for FunctionDeclMatchHandler in main.cpp.o
"typeinfo for clang::ASTFrontendAction", referenced from:
typeinfo for XUnusedFrontendAction in main.cpp.o
"typeinfo for clang::tooling::FrontendActionFactory", referenced from:
typeinfo for XUnusedFrontendActionFactory in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
gnumake[2]: *** [xunused] Error 1
gnumake[1]: *** [CMakeFiles/xunused.dir/all] Error 2
gnumake: *** [all] Error 2
robb@Robs-MacBook-Pro:~/SkunkWorks/xunused/build (master)$

Do I need to build llvm from scratch with rtti turned on?

Getting Linking error When building xunused with llvm 10.0

~/workspace/waa_dev/xunused \ue0b0 \ue0a0 * \ue0b0 build \ue0b0 make 765ms \ue0b3 Tue Oct 12 06:27:00 2021
Scanning dependencies of target xunused
[ 50%] Building CXX object CMakeFiles/xunused.dir/main.cpp.o
[100%] Linking CXX executable xunused
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI28XUnusedFrontendActionFactory[_ZTI28XUnusedFrontendActionFactory]+0x10): undefined reference to typeinfo for clang::tooling::FrontendActionFactory' /bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI21XUnusedFrontendAction[_ZTI21XUnusedFrontendAction]+0x10): undefined reference to typeinfo for clang::ASTFrontendAction'
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI18XUnusedASTConsumer[_ZTI18XUnusedASTConsumer]+0x10): undefined reference to typeinfo for clang::ASTConsumer' /bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI24FunctionDeclMatchHandler[_ZTI24FunctionDeclMatchHandler]+0x10): undefined reference to typeinfo for clang::ast_matchers::MatchFinder::MatchCallback'
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTIN4llvm9ErrorInfoINS_9ErrorListENS_13ErrorInfoBaseEEE[_ZTIN4llvm9ErrorInfoINS_9ErrorListENS_13ErrorInfoBaseEEE]+0x10): undefined reference to `typeinfo for llvm::ErrorInfoBase'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/xunused.dir/build.make:108: xunused] Error 1
make[1]: *** [CMakeFiles/Makefile2:79: CMakeFiles/xunused.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Doesn't compile on clang 18.1

[ 50%] Building CXX object CMakeFiles/xunused.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -I/opt/llvm18/include -I/opt/include -I /opt/openssl-3.2.1/include -O3 -march=native -funroll-loops -finline-functions -mtune=native -Wno-everything -O3 -DNDEBUG -std=gnu++17 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -mmacosx-version-min=14.4 -fcolor-diagnostics   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -MD -MT CMakeFiles/xunused.dir/main.cpp.o -MF CMakeFiles/xunused.dir/main.cpp.o.d -o CMakeFiles/xunused.dir/main.cpp.o -c /xunused/main.cpp
/xunused/main.cpp:178:37: error: no member named 'isPure' in 'clang::CXXMethodDecl'
        if (MD->isVirtual() && !MD->isPure() && MD->size_overridden_methods())
                                ~~  ^
1 error generated.
make[2]: *** [CMakeFiles/xunused.dir/build.make:76: CMakeFiles/xunused.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/xunused'
make[1]: *** [CMakeFiles/Makefile2:218: CMakeFiles/xunused.dir/all] Error 2
make[1]: Leaving directory '/xunused'
make: *** [Makefile:136: all] Error 2

Fails loading database

First attempt to use xunused, following the instructions in READ.me, fails:

$ bear --output /io/h.json -- ninja
$ /Gext/xunused/build/xunused /io/h.json 
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/io/h.json"
No compilation database found in /io or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.