rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.96k stars 321 forks source link

Support link commands in the output #276

Open rizsotto opened 4 years ago

rizsotto commented 4 years ago

There is a documented use case for this feature immunant/c2rust#227

PolyProgrammist commented 3 years ago

Hi! We have drawn a format for link commands format

We also have worked on this for CMake issue pull request

Also, we have some work for bear, it needs a bit more work to make it public

Please feel free to comment the link database format here or in CMake issue

rizsotto commented 3 years ago

Hey @PolyProgrammist, thanks for your comment.

Until the official definition of the JSON compilation database does not accommodate the link commands explicitly, I would emit the link command in a backward compatible way. (The c2rust solution looks like a good candidate for that.)

If Bear would emit a new format, I would like to call that something else, but not "JSON compilation database" to avoid confusion.

If Bear would emit a new format, I would like to onboard different build steps not only compilation and linking. My suggestion would be to describe the build in an ontology. (The file format can be anything like turtle or n3.) An ontology is a flexible knowledge representation, which can be extended easily, so can contain not only compilation or link commands, but which source file contains what function declaration, or what header files the source file includes, or even the call graph can be described in it. That could be a much detailed description of a software project. And would open possibilities for new use cases: can merge two dependent project's ontology without problem, and run cross project analysis. (That would catch bugs of new kind, when developers not using another project API correctly. And having fewer mono-repo project this can be relevant.) It can help to automate build system migrations, etc...

KevinIsSun commented 2 years ago

Hi @rizsotto , do we have a roadmap for this feature? Or do we have any design doc which can be public? Thanks a lot.

rizsotto commented 2 years ago

@KevinIsSun are you asking about to implement the link command in the output as c2rust project suggest? The design doc is only the immunant/c2rust#227 ticket discussion. (Can expand that into a more detailed wiki page.) Are you interested to help with the implementation?

KevinIsSun commented 2 years ago

Yeah, I want to get link command in the output of bear. I have read the whole related discussion, but it's far away from a real feature. I'm interested in the implementation, but I'm not familiar with the code of bear. I'm not sure how much time will spent on it. I think we need a design doc first.

tr4v3ler commented 2 years ago

Someone once implemented the capture of the link command on an old bear version. The link is as follows: bear Hope to provide some reference.

tr4v3ler commented 2 years ago

The following output is a case:

"arguments": [
    "-EL",
    "-r"
],
"directory": "/home/tr4v3ler/data/tools/difuze/mtk_kernel_0/kernel-3.18/out",
"files": [
    "drivers/misc/mediatek/video/common/mtkfb_fence.o", 
    "drivers/misc/mediatek/video/common/fbconfig_kdebug.o", 
    "drivers/misc/mediatek/video/common/aal20/built-in.o", 
    "drivers/misc/mediatek/video/common/corr10/built-in.o", 
    "drivers/misc/mediatek/video/common/color20/built-in.o"
],
"loader": "ld",  
"output": [
    "-o",
    "drivers/misc/mediatek/video/common/built-in.o"
]

There are many modules in the Linux kernel. I can't analyze the code of the whole module through a single object file, so I need to get the link command to generate the linked bitcode file through llvm and then complete the code analysis. But I'm not familiar with the source code of bear. I don't know where to modify it.