Skip to content

Commit b96e53c

Browse files
authored
Release v1.16.1 (#275)
1 parent 044f675 commit b96e53c

File tree

11 files changed

+144
-19
lines changed

11 files changed

+144
-19
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ jobs:
249249
run: docker build --progress=plain --platform ${{ matrix.target.platform }} --build-arg "ARCH=${{ matrix.target.arch }}" -f docker/libddwaf/smoketest/musl_llvm/Dockerfile .
250250
- name: Smoketest gnu (gcc)
251251
run: docker build --progress=plain --platform ${{ matrix.target.platform }} --build-arg "ARCH=${{ matrix.target.arch }}" -f docker/libddwaf/smoketest/gnu/Dockerfile .
252+
- name: Smoketest gnu rhel 6 (gcc)
253+
if: matrix.target.qemu_action_arch == 'amd64'
254+
run: docker build --progress=plain --platform ${{ matrix.target.platform }} --build-arg "ARCH=${{ matrix.target.arch }}" -f docker/libddwaf/smoketest/gnu_rhel6/Dockerfile .
252255
- name: Generate Package sha256
253256
working-directory: packages
254257
run: for file in *.tar.gz; do sha256sum "$file" > "$file.sha256"; done

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# libddwaf release
2+
### v1.16.1 ([unstable](https://github.com/DataDog/libddwaf/blob/master/README.md#versioning-semantics))
3+
### Fixes
4+
- Add support for old glibc (e.g. RHEL 6) ([#262](https://github.com/DataDog/libddwaf/pull/262))
5+
- Add weak ceilf symbol and definition ([#263](https://github.com/DataDog/libddwaf/pull/263))
6+
27
### v1.16.0 ([unstable](https://github.com/DataDog/libddwaf/blob/master/README.md#versioning-semantics))
38
#### Fixes
49
- Address a libinjection false positive ([#251](https://github.com/DataDog/libddwaf/pull/pull/251))

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ endif()
4747

4848
include(GNUInstallDirs)
4949

50-
add_library(glibc_compat OBJECT ${libddwaf_SOURCE_DIR}/src/glibc-compat/time64.c)
51-
set_target_properties(glibc_compat PROPERTIES POSITION_INDEPENDENT_CODE 1)
50+
add_library(glibc_compat_time64 OBJECT ${libddwaf_SOURCE_DIR}/src/glibc-compat/time64.c)
51+
set_target_properties(glibc_compat_time64 PROPERTIES POSITION_INDEPENDENT_CODE 1)
52+
53+
add_library(glibc_compat_math OBJECT ${libddwaf_SOURCE_DIR}/src/glibc-compat/math.c)
54+
set_target_properties(glibc_compat_math PROPERTIES POSITION_INDEPENDENT_CODE 1)
5255

5356
try_compile(STDLIB_MAP_RECURSIVE ${CMAKE_CURRENT_BINARY_DIR}
5457
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/try_rec_map.cpp
@@ -68,8 +71,7 @@ if(LINUX)
6871
set(LIBDDWAF_INTERFACE_LIBRARIES
6972
$<$<BOOL:${LIBPTHREAD}>:pthread>
7073
$<$<BOOL:${LIBRT}>:rt>
71-
$<$<BOOL:${LIBDL}>:dl>
72-
$<$<BOOL:${LIBM}>:m>)
74+
$<$<BOOL:${LIBDL}>:dl>)
7375
elseif(WIN32)
7476
list(APPEND LIBDDWAF_INTERFACE_LIBRARIES ws2_32)
7577
endif()

cmake/shared.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if(LINUX)
2525
-Wl,--build-id=0x${BUILD_ID}
2626
${LIBDDWAF_PRIVATE_LIBRARIES}
2727
-static-libstdc++
28-
glibc_compat)
28+
glibc_compat_time64 glibc_compat_math)
2929

3030
if(NOT (CMAKE_BUILD_TYPE MATCHES Debug))
3131
set(SYMBOL_FILE $<TARGET_FILE:libddwaf_shared>.debug)
@@ -79,5 +79,5 @@ elseif (MINGW)
7979
-Wl,--build-id=0x${BUILD_ID}
8080
${LIBDDWAF_PRIVATE_LIBRARIES}
8181
-static-libstdc++
82-
glibc_compat)
82+
glibc_compat_time64 glibc_compat_math)
8383
endif()

cmake/static.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ install(TARGETS libddwaf_static EXPORT libddwaf-config
1313

1414
# Post-processing on the static library
1515
if(LINUX)
16-
add_dependencies(libddwaf_static glibc_compat)
16+
add_dependencies(libddwaf_static glibc_compat_time64 glibc_compat_math)
1717
add_custom_command(TARGET libddwaf_static POST_BUILD
1818
COMMAND ${CMAKE_COMMAND} -E make_directory ar_comb
1919
COMMAND ${CMAKE_COMMAND} -E chdir ar_comb ${CMAKE_AR} -x $<TARGET_FILE:libddwaf_static>
20-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:glibc_compat> ar_comb
20+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:glibc_compat_time64> ar_comb
21+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:glibc_compat_math> ar_comb
2122
COMMAND ${CMAKE_AR} -qcs ar_comb/combined${CMAKE_STATIC_LIBRARY_SUFFIX} ar_comb/*.o*
2223

2324
COMMAND ${CMAKE_COMMAND} -E copy ar_comb/combined${CMAKE_STATIC_LIBRARY_SUFFIX} $<TARGET_FILE:libddwaf_static>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM quay.io/pypa/manylinux2010_x86_64:latest AS smoketest
2+
3+
ARG ARCH
4+
5+
COPY packages/ /packages
6+
COPY smoketest /smoketest
7+
8+
RUN yum -y install gcc cmake make
9+
10+
RUN tar -kxf packages/libddwaf-*-${ARCH}-linux-*.tar.gz --strip-components=1
11+
RUN ln -s /lib/libddwaf.* /lib64/
12+
13+
RUN mkdir build_static && cd build_static && \
14+
cmake -DCMAKE_C_FLAGS="-I/include" \
15+
-DLIBDDWAF_SMOKE_LINK_STATIC=ON /smoketest && \
16+
make && ./smoketest
17+
18+
RUN mkdir build_shared && cd build_shared && \
19+
cmake -DCMAKE_C_FLAGS="-I/include" \
20+
-DLIBDDWAF_SMOKE_LINK_STATIC=OFF /smoketest && \
21+
make && ./smoketest
22+

docker/libddwaf/sysroot/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ RUN cd llvm-project-${LLVM_VERSION}.src && mkdir -p build && cd build && \
1818
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
1919
-DCMAKE_INSTALL_PREFIX=/usr \
2020
-DCMAKE_C_COMPILER=clang \
21-
-DCMAKE_C_FLAGS=-fno-omit-frame-pointer \
21+
-DCMAKE_C_FLAGS="-fno-omit-frame-pointer -D_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC=1" \
2222
-DCMAKE_CXX_COMPILER=clang++ \
23-
-DCMAKE_CXX_FLAGS=-fno-omit-frame-pointer \
23+
-DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -D_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC=1" \
2424
-DLIBUNWIND_ENABLE_SHARED=OFF \
2525
-DLIBUNWIND_ENABLE_STATIC=ON \
2626
-DLIBUNWIND_USE_COMPILER_RT=ON \

smoketest/smoke.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdint.h>
55
#include <inttypes.h>
66
#include <string.h>
7+
#include <math.h>
78

89
static ddwaf_object *prepare_rule() {
910
ddwaf_object *ret = malloc(sizeof *ret);
@@ -244,5 +245,6 @@ int main() {
244245
return 1;
245246
}
246247
puts("result is valid");
248+
247249
return 0;
248250
}

src/glibc-compat/math.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Unless explicitly stated otherwise all files in this repository are
2+
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License.
3+
//
4+
// This product includes software developed at Datadog
5+
// (https://www.datadoghq.com/). Copyright 2023 Datadog, Inc.
6+
7+
#if defined(__linux__)
8+
9+
#ifndef _GNU_SOURCE
10+
#define _GNU_SOURCE
11+
#endif
12+
#include <dlfcn.h>
13+
#include <stdint.h>
14+
#include <stdlib.h>
15+
16+
#if defined(__aarch64__)
17+
// Extracted from https://git.musl-libc.org/cgit/musl/tree/src/math/aarch64/ceilf.c
18+
static float ceilf_local(float x)
19+
{
20+
__asm__ ("frintp %s0, %s1" : "=w"(x) : "w"(x));
21+
return x;
22+
}
23+
#else
24+
/* fp_force_eval ensures that the input value is computed when that's
25+
otherwise unused. To prevent the constant folding of the input
26+
expression, an additional fp_barrier may be needed or a compilation
27+
mode that does so (e.g. -frounding-math in gcc). Then it can be
28+
used to evaluate an expression for its fenv side-effects only. */
29+
30+
static inline void fp_force_evalf(float x)
31+
{
32+
volatile float y;
33+
y = x;
34+
(void)y;
35+
}
36+
37+
static float ceilf_local(float x)
38+
{
39+
// Extracted from https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
40+
union {float f; uint32_t i;} u = {x};
41+
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
42+
uint32_t m;
43+
44+
if (e >= 23) {
45+
return x;
46+
}
47+
if (e >= 0) {
48+
m = 0x007fffff >> e;
49+
if ((u.i & m) == 0) {
50+
return x;
51+
}
52+
fp_force_evalf(x + 0x1p120f);
53+
if (u.i >> 31 == 0){
54+
u.i += m;
55+
}
56+
u.i &= ~m;
57+
} else {
58+
fp_force_evalf(x + 0x1p120f);
59+
if (u.i >> 31) {
60+
u.f = -0.0;
61+
} else if (u.i << 1) {
62+
u.f = 1.0;
63+
}
64+
}
65+
return u.f;
66+
}
67+
#endif
68+
69+
#define unlikely(x) __builtin_expect(!!(x), 0)
70+
71+
typedef float (*ceilf_t)(float);
72+
73+
__attribute__((weak))
74+
float ceilf(float x)
75+
{
76+
static ceilf_t ceilf_global_;
77+
78+
// benign race
79+
if (unlikely(ceilf_global_ == NULL)) {
80+
void *ceilf_sym = dlsym(RTLD_DEFAULT, "ceilf");
81+
if (ceilf_sym == NULL || ceilf_sym == &ceilf) {
82+
ceilf_global_ = &ceilf_local;
83+
} else {
84+
ceilf_global_ = (ceilf_t)ceilf_sym;
85+
}
86+
}
87+
return ceilf_global_(x);
88+
}
89+
#endif
90+

src/glibc-compat/time64.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
// This product includes software developed at Datadog
55
// (https://www.datadoghq.com/). Copyright 2023 Datadog, Inc.
66

7-
#include <stdlib.h>
8-
97
#if defined(__linux__) && !defined(__GLIBC__) && (defined(__arm__) || defined(__i386__))
108

9+
#include <stdlib.h>
1110
#include <features.h>
1211

1312
__attribute__((weak))
@@ -16,6 +15,7 @@ int __nanosleep64(void *req, void *rem) {
1615
(void) rem;
1716
abort();
1817
}
18+
1919
__attribute__((weak))
2020
int __nanosleep_time64(void *req, void *rem) {
2121
return __nanosleep64(req, rem);
@@ -28,19 +28,19 @@ int __pthread_cond_timedwait64(void *cond, void *mutex, void *abstime) {
2828
(void) abstime;
2929
abort();
3030
}
31+
3132
__attribute__((weak))
3233
int __pthread_cond_timedwait_time64(void *cond, void *mutex, void *abstime) {
3334
return __pthread_cond_timedwait64(cond, mutex, abstime);
3435
}
3536

36-
__attribute__((weak))
37-
void *dlsym(void * handle, const char *name) {
38-
(void) handle;
39-
(void) name;
40-
abort();
41-
}
37+
void *dlsym(void * handle, const char *name);
38+
39+
// use weak attribute so that on static builds there is no indirection
4240
__attribute__((weak))
4341
void *__dlsym_time64(void *handle, const char *name) {
42+
// no problem calling the plain dlsym as we don't use the function for which
43+
// it would make a difference
4444
return dlsym(handle, name);
4545
}
4646

0 commit comments

Comments
 (0)