Commit graph

143 commits

Author SHA1 Message Date
Micah Snyder (micasnyd)
b9ca6ea103 Update copyright dates for 2021
Also fixes up clang-format.
2021-03-19 15:12:26 -07:00
Micah Snyder (micasnyd)
9e20cdf6ea Add CMake build tooling
This patch adds experimental-quality CMake build tooling.

The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.

Removed use of libltdl when using CMake.

Flex & Bison are now required to build.

If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything.  TODO!

I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.

CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.

Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.

For example, ...

```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```

... becomes:

```c
// libclamav
include "clamav.h"

// clamd
include "clamd_others.h"
```

Fixes header name conflicts by renaming a few of the files.

Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.

libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.

Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.

Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.

The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.

Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.

Generate common.rc for win32.

Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.

Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.

clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
  similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
  the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.

Updates to clamdscan man page, add missing options.

Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).

Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Micah Snyder
52cddcbcfd Updating and cleaning up copyright notices. 2019-10-02 16:08:18 -04:00
Micah Snyder
dd2ed14ddb adding a few minor changes to eliminate warnings, the most interesting of which was a missing function prototype for cache_get_MD5. 2017-08-10 15:40:52 -04:00
Steven Morgan
22cb38ed24 pull request #53(2/4): Spelling fix by klemens(ka7). 2016-10-19 15:57:45 -04:00
Kevin Lin
d6699b050a fix make check issue with llvm builds with assertion 2016-02-29 11:05:19 -05:00
Kevin Lin
2c859ec754 bb#11414 - integrate patch for LLVM 3.6 support 2015-10-29 17:48:45 -04:00
Mickey Sola
46a35abe56 mass update of copyright headers 2015-09-17 13:41:26 -04:00
Kevin Lin
99aeada848 bb#11147 - reverted change overwritten with branch merging
ref commit "rolled back changes from bb#8352 - fixes ppc unit tests"
2014-10-17 11:06:30 -04:00
Kevin Lin
4a40b53a1c bb#11146 - applied patch for system LLVM 3.5.0 support 2014-10-17 10:49:06 -04:00
Kevin Lin
deafd8fa94 bb#11112 - fixed custom pass initialization when using LLVM 2.9 2014-09-29 17:32:00 -04:00
Kevin Lin
ccc94d9003 added kfreebsd* to target OS
hardcoded embedded llvm version to 2.8
changed supported system-llvm 2.9 -> 3.4.1
minor compilation changes
2014-07-25 14:19:40 -04:00
Kevin Lin
b331b610bf added bytecode2llvm conversion for OP_BC_ICMP_SLE instruction 2014-07-25 12:55:01 -04:00
Kevin Lin
9f8df4ae4b unified bytecode version macros into LLVM_VERSION macro 2014-07-25 12:47:18 -04:00
Kevin Lin
fb2b05cb4a bytecode: merged in changes since 0.98.1 2014-07-25 12:29:08 -04:00
Kevin Lin
34d8b8cfc7 bb#10981 - applied LLVM 3.1-3.4 patch for testing
Conflicts:

	libclamav/c++/Makefile.am
	libclamav/c++/bytecode2llvm.cpp
2014-07-25 12:26:04 -04:00
Shawn Webb
60d8d2c352 Move all the crypto API to clamav.h 2014-07-01 19:38:01 -04:00
Kevin Lin
09317562d9 rolled back changes from bb#8352 - fixes ppc unit tests 2014-06-02 10:52:01 -04:00
Shawn Webb
b2e7c931d0 Use OpenSSL for hashing. 2014-02-08 00:31:12 -05:00
Kevin Lin
51abf545de bb#8352 - converted serveral llvm intrinsics functions to 64-bit from 32-bit to correct type mismatch with bytecode compiler 2013-10-21 14:05:31 -07:00
David Raynor
3609e2d7b8 bytecode: cid #10622 2013-08-15 16:42:19 -04:00
David Raynor
9e1f0d90ad bytecode: refactored cleanup on error exit paths, cid #10509 & #10510 2013-08-15 16:23:44 -04:00
David Raynor
3aca6c4afe JIT: some better cleanup on error returns (also cid #10509 & #10510 & #10512), though these paths should lead to exit anyway 2013-08-09 18:33:06 -04:00
David Raynor
bebd86a60b bb#5343 2012-06-22 16:55:29 -04:00
Török Edvin
872d0a90d6 more LLVM 3.0 API changes 2011-10-26 00:05:17 +03:00
Török Edvin
59f1b78b51 Support LLVM 3.0 API 2011-09-30 15:32:16 +03:00
Török Edvin
bb5572cbe1 bytecode_watchdog: fix use of unaddressable data
If the watchdog thread is sleeping on a watchdog_item and
vm_execute_jit calls watchdog_disarm and returns before the watchdog wakes up,
then the watchdog thread will wake up and try to use the now uninitialized
item->abs_timeout.

Fix this by adding an in_use flag, and another condition variable.
watchdog_disarm now wakes the watchdog thread,
and waits till it releases the item.

Thanks to Michael Scheidell for providing feedback on this bug.
2011-06-30 14:28:44 +03:00
Török Edvin
b6187b6330 attempt to fix win32 build 2011-05-06 21:26:55 +03:00
Török Edvin
0c79cc5529 Support building with external LLVM 2.9, and drop support for building with external 2.8
Internal version is an LLVM 2.8 with 2 patches backported from LLVM 2.9 to fix a
crash on AVX chips.
So drop support for building with external LLVM 2.8, and add support for
building with external LLVM 2.9 instead.

Caveat:
 stack smashing protection is broken on LLVM 2.9 so it is disabled

Example on Debian:
apt-get install llvm-2.9-dev
./configure --enable-llvm --with-system-llvm=/usr/bin/llvm-config-2.9
2011-05-06 16:16:33 +03:00
Török Edvin
e51fc0581e bytecode: reuse watchdog thread
Don't create a new watchdog thread everytime a bytecode is run.
Instead try to reuse a previously create watchdog thread.
Watchdog thread will idle for a max of 10s, and then exit, and new watchdog being
created as needed.
2011-04-15 15:06:11 +03:00
Török Edvin
ab402e6aae Speed up bytecode load.
Don't codegen bytecodes that have a functionality_level test in entrypoint
that would prevent them from running.
2011-01-20 16:10:30 +02:00
aCaB
26b86d8d8e add missing EOL 2011-01-20 15:04:51 +01:00
Török Edvin
ce2386732a Fix build with external LLVM28.
It declares those 2 initialize functions as C linkage, so make sure we match it
(in our version they are not declared at all).
2010-11-12 09:53:09 +02:00
Török Edvin
e92dda94ce chkstk: another try. 2010-11-10 16:21:48 +02:00
Török Edvin
3d8ca9f6aa chkstk 2010-11-10 16:19:59 +02:00
Török Edvin
ca3e6c5860 I'm told _chkstk needs to be called as __chkstk on Win64.
Same to the backend (added _), but if I want the linker to find it, I need to do
it like this. Hope it works.
2010-11-10 16:00:39 +02:00
Török Edvin
3a35520bf9 Fix recently introduced ScopedExceptionHandler.
can't use setjmp inside a function that is not the parent.
just write and use some macros.

Otherwise the "else" from handler.Set() was never reached, which caused a unit
test to fail.
2010-11-10 14:53:39 +02:00
Török Edvin
29553b8e26 bytecode2llvm: convert errs() to cli_{err,warn,dbg} so they are not lost. 2010-11-10 14:21:51 +02:00
Török Edvin
4955886036 Fix win32 bytecode: allow _chkstk.
Win32 needs this when stack >4k, this was the message that was logged to stderr
previously, causing the crash.
2010-11-10 14:21:51 +02:00
Török Edvin
f62d53980a bytecode2llvm: make sure we don't return from a NORETURN function. 2010-11-10 14:21:50 +02:00
Török Edvin
162c2e431b bytecode2llvm: don't crash when stderr is unavailable.
Writing to errs() when stderr is not open results in write Error getting flagged
in LLVM's raw_fd_ostream, which results in a call to llvm_report_error.
However since jmp_buf is not valid anymore we end up crashing on longjmp.

Fix:
 - reset the thread-local recovery (jmp_buf*) to NULL when exiting the block
 where it is valid
 - clear errors on errs() on shutdown to avoid the report_fatal_error
2010-11-10 14:21:47 +02:00
Török Edvin
dccafff069 define LLVM28, since we are using that now. 2010-11-06 15:50:31 +02:00
Török Edvin
a7cf187a0c Make cl_load thread safe (bb #2333).
Parallel cl_load() crash (bb #2333).
Reason is twofold:
 - cache.c had 2 'static' global variables, thus trying to initialize same cache
 from multiple threads
  - bytecode2llvm.cpp: something in LLVM 2.7 is crashing when loading in
  parallel

Fix is to drop the 'static' on the variable (cache is per engine already).
This also fixes a potential memory leak in clamd!

The other part of the fix is to turn on the mutex around bytecode compilation
always. We don't call cl_load in parallel, so this doesn't affect clamd, but
some may need to call cl_load in parallel.
2010-11-04 21:53:03 +02:00
Török Edvin
49eb01089a Make sure Functions[i] is initialized, and not used as NULL. 2010-10-22 12:31:53 +03:00
Török Edvin
34306523a1 Fix startup.cbc load (bb #2330).
BC_STARTUP is already prepared with JIT, so Functions[i] is garbage,
don't attempt to codegen it.
2010-10-18 13:45:20 +03:00
Török Edvin
dec93ea86f Fix bytecode and autoitea06 for Apple-style universal builds (bb #2030)
Bytecode needs to enable both PPC and X86, link in all targets,
and autoit needs fpu_endian == cpu_endian for universal builds.
2010-10-18 11:27:06 +03:00
Török Edvin
1755adf042 Fix build with internal LLVM. 2010-09-28 16:43:25 +03:00
Török Edvin
45ba739216 Fix constructors for LLVM 2.8. 2010-09-28 14:45:04 +03:00
Török Edvin
b22af13f7a Merge branch 'llvm2.8'
* llvm2.8:
  Regenerate configure and Makefile.
  LLVM 2.8 changed llvm.mem{cpy,move,set}.* to take 5 arguments.
  LLVM 2.8 API update.
  Don't cast the iterator directly.
  Use CallSite instead of CI->getOperand.
  Support building with external LLVM 2.8.

Conflicts:
	libclamav/c++/Makefile.in
	libclamav/c++/bytecode2llvm.cpp
	libclamav/c++/configure
2010-09-28 14:28:59 +03:00