-
Notifications
You must be signed in to change notification settings - Fork 13
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
llc only supports one input file #36
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -753,14 +753,26 @@ function(llvmir_attach_obj_target) | |
list(APPEND IN_FULL_LLVMIR_FILES "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") | ||
endforeach() | ||
|
||
set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${TRGT}.o") | ||
if(SHORT_NAME) | ||
set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${SHORT_NAME}.o") | ||
endif() | ||
get_filename_component(OUT_LLVMIR_FILE ${FULL_OUT_LLVMIR_FILE} NAME) | ||
foreach(IN_LLVMIR_FILE ${IN_FULL_LLVMIR_FILES}) | ||
get_filename_component(OUTFILE ${IN_LLVMIR_FILE} NAME_WE) | ||
set(OUT_LLVMIR_FILE "${OUTFILE}.o") | ||
set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${OUT_LLVMIR_FILE}") | ||
|
||
list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) | ||
list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) | ||
add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} | ||
COMMAND llc | ||
ARGS | ||
-filetype=obj | ||
-relocation-model=pic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this flag here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this flag because the compiler complained in my real project that I needed to recompile with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not have project-specific options hardcoded like this. Can you please try your project with defining that flag in your |
||
-o=${FULL_OUT_LLVMIR_FILE} | ||
${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} | ||
${IN_LLVMIR_FILE} | ||
DEPENDS ${IN_LLVMIR_FILE} | ||
COMMENT "Generating object ${OUT_LLVMIR_FILE}" | ||
VERBATIM) | ||
|
||
list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) | ||
list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) | ||
endforeach() | ||
|
||
# setup custom target | ||
add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) | ||
|
@@ -786,16 +798,6 @@ function(llvmir_attach_obj_target) | |
set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) | ||
set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) | ||
|
||
add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} | ||
COMMAND llc | ||
ARGS | ||
-filetype=obj | ||
${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} | ||
-o ${FULL_OUT_LLVMIR_FILE} ${IN_FULL_LLVMIR_FILES} | ||
DEPENDS ${IN_FULL_LLVMIR_FILES} | ||
COMMENT "Generating object ${OUT_LLVMIR_FILE}" | ||
VERBATIM) | ||
|
||
## postamble | ||
endfunction() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# cmake file | ||
|
||
cmake_minimum_required(VERSION 3.9) | ||
|
||
find_program(CMAKE_C_COMPILER clang) | ||
find_program(CMAKE_CXX_COMPILER clang++) | ||
|
||
project(staticlib) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") | ||
|
||
message(STATUS ${CMAKE_MODULE_PATH}) | ||
include(LLVMIRUtil) | ||
|
||
add_subdirectory(staticlib) | ||
add_subdirectory(executable) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Instrumenting an static library | ||
|
||
```sh | ||
mkdir build && cd build | ||
cmake .. | ||
make testlib_instrumented | ||
make main | ||
./executable/main | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_executable(main main.c) | ||
target_include_directories(main PUBLIC "./../staticlib/include") | ||
target_link_libraries(main "${CMAKE_BINARY_DIR}/staticlib/libtestlib_instrumented.a") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "Test1.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
puts("Calling Test1 from static lib!"); | ||
Test1(); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set(CMAKE_BUILD_TYPE Debug) | ||
# set(LLVM_PASS_PLUGIN "<filepath to llvm plugin pass>") | ||
|
||
set(SOURCE_FILES | ||
src/Test1.c | ||
src/Test2.c | ||
src/Test3.c | ||
) | ||
|
||
add_library(testlib STATIC ${SOURCE_FILES}) | ||
target_include_directories(testlib PUBLIC "./include") | ||
set_target_properties(testlib PROPERTIES LINKER_LANGUAGE C) | ||
|
||
llvmir_attach_bc_target(testlib_bc testlib) | ||
llvmir_attach_opt_pass_target(testlib_opt testlib_bc) # -load-pass-plugin=${LLVM_PASS_PLUGIN} -passes=ctrace) | ||
|
||
llvmir_attach_obj_target(testlib_obj testlib_opt) | ||
llvmir_attach_library(testlib_instrumented testlib_obj STATIC) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <stdlib.h> | ||
#include "Test2.h" | ||
|
||
void Test1(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "Test3.h" | ||
#include <stdio.h> | ||
|
||
void Test2(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <stdio.h> | ||
|
||
void Test3(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Test1.h" | ||
|
||
void Test1() | ||
{ | ||
puts("Test1 called"); | ||
Test2(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Test2.h" | ||
|
||
void Test2() | ||
{ | ||
puts("Test2 called!"); | ||
Test3(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "Test3.h" | ||
|
||
void Test3() | ||
{ | ||
puts("Test3 called"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
SHORT_NAME
still useful for the multiple output files generated by the changes in your PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my project it worked fine without it, so I assumed that I could just remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please reintroduce it and check that your project still works?
Just because it's not needed in your configuration doesn't mean that wasn't introduced for a reason initially.