Browse Source

[Minor] Fix clang plugin functions on OSX

tags/2.1
Vsevolod Stakhov 4 years ago
parent
commit
5c8a82ded1
4 changed files with 29 additions and 14 deletions
  1. 10
    6
      clang-plugin/CMakeLists.txt
  2. 16
    5
      clang-plugin/printf_check.cc
  3. 1
    1
      src/CMakeLists.txt
  4. 2
    2
      src/libserver/task.c

+ 10
- 6
clang-plugin/CMakeLists.txt View File

@@ -1,6 +1,5 @@

IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
cmake_minimum_required(VERSION 3.9)
# Clang plugin for static analysis
PROJECT(RspamdClangPlugin)
if (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
@@ -14,6 +13,13 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
ADD_DEFINITIONS(${LLVM_DEFINITIONS})

find_package(Clang REQUIRED)

set(clang_libs
clangAST
clangBasic
clangFrontend)

message(STATUS "Found LibClang in: ${CLANG_INSTALL_PREFIX}")
include_directories(${CLANG_INCLUDE_DIRS})

SET(CLANGPLUGINSRC plugin.cc printf_check.cc)
@@ -22,7 +28,9 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
SET_TARGET_PROPERTIES(rspamd-clang PROPERTIES
COMPILE_FLAGS "-O2 -Wall -Wextra -Wno-unused-parameter -Werror"
LINKER_LANGUAGE CXX)
set_property(TARGET rspamd-clang APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined -Wl,--as-needed")
IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_property(TARGET rspamd-clang APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined -Wl,--as-needed")
ENDIF()

find_library(found_LLVM LLVM HINTS ${LLVM_LIBRARY_DIRS})
if(found_LLVM)
@@ -33,9 +41,5 @@ IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
target_link_libraries(rspamd-clang PRIVATE ${llvm_libs})
endif()

set(clang_libs
clangAST
clangBasic
clangFrontend)
target_link_libraries(rspamd-clang PRIVATE ${clang_libs})
ENDIF()

+ 16
- 5
clang-plugin/printf_check.cc View File

@@ -590,11 +590,22 @@ namespace rspamd {
size_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
{
if (sizeof (size_t) == sizeof (long)) {
return check_builtin_type (arg,
ctx,
{BuiltinType::Kind::ULong,
BuiltinType::Kind::Long},
"%z");
if (sizeof (long long) == sizeof (long)) {
return check_builtin_type (arg,
ctx,
{BuiltinType::Kind::ULong,
BuiltinType::Kind::Long,
BuiltinType::Kind::LongLong,
BuiltinType::Kind::ULongLong},
"%z");
}
else {
return check_builtin_type (arg,
ctx,
{BuiltinType::Kind::ULong,
BuiltinType::Kind::Long},
"%z");
}
}
else if (sizeof (size_t) == sizeof (int)) {
return check_builtin_type (arg,

+ 1
- 1
src/CMakeLists.txt View File

@@ -63,7 +63,7 @@ ENDMACRO(AddModules MLIST WLIST)
# Rspamd core components
IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
SET(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -Xclang -load -Xclang ${CMAKE_CURRENT_BINARY_DIR}/../clang-plugin/librspamd-clang.so -Xclang -add-plugin -Xclang rspamd-ast")
"${CMAKE_C_FLAGS} -Xclang -load -Xclang ${CMAKE_CURRENT_BINARY_DIR}/../clang-plugin/librspamd-clang${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang rspamd-ast")
IF(CLANG_EXTRA_PLUGINS_LIBS)
FOREACH(_lib ${CLANG_EXTRA_PLUGINS_LIBS})
SET(CMAKE_C_FLAGS

+ 2
- 2
src/libserver/task.c View File

@@ -395,7 +395,7 @@ rspamd_task_load_message (struct rspamd_task *task,

if (offset > (gulong)st.st_size) {
msg_err_task ("invalid offset %ul (%ul available) for shm "
"segment %s", offset, st.st_size, fp);
"segment %s", offset, (gulong)st.st_size, fp);
munmap (map, st.st_size);
close (fd);

@@ -412,7 +412,7 @@ rspamd_task_load_message (struct rspamd_task *task,

if (shmem_size > (gulong)st.st_size) {
msg_err_task ("invalid length %ul (%ul available) for %s "
"segment %s", shmem_size, st.st_size, ft, fp);
"segment %s", shmem_size, (gulong)st.st_size, ft, fp);
munmap (map, st.st_size);
close (fd);


Loading…
Cancel
Save