Skip to content

Commit

Permalink
Handle zstd not being present on Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed May 25, 2024
1 parent 7b53098 commit d0f6d50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,17 @@ set(REQUIRED_LIBS
capnp
# zlib is required to handle ELF compression
zlib
# zstd is required to handle ELF compression
libzstd
)

if(NOT ANDROID)
set(REQUIRED_LIBS
${REQUIRED_LIBS}
# zstd is required to handle ELF compression, but isn't available on Android.
libzstd
)
add_definitions(-DZSTD=1)
endif()

foreach(required_lib ${REQUIRED_LIBS})
string(TOUPPER ${required_lib} PKG)
if(NOT SKIP_PKGCONFIG)
Expand Down Expand Up @@ -715,10 +722,13 @@ endif()
target_link_libraries(rr
${CMAKE_DL_LIBS}
${ZLIB_LDFLAGS}
${LIBZSTD_LDFLAGS}
brotli
)

if(NOT ANDROID)
target_link_libraries(rr ${LIBZSTD_LDFLAGS})
endif()

if(staticlibs)
# Urgh ... this might not work for everyone, but there doesn't seem to be
# a way to persuade pkg-confing/pkg_check_modules to produce the right flags
Expand Down
4 changes: 4 additions & 0 deletions src/ElfReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <zlib.h>
#ifdef ZSTD
#include <zstd.h>
#endif

#include "log.h"
#include "util.h"
Expand Down Expand Up @@ -238,13 +240,15 @@ const vector<uint8_t>* ElfReaderImpl<Arch>::decompress_section(SectionOffsets of
FATAL() << "inflateEnd failed!";
return nullptr;
}
#ifdef ZSTD
} else if (zstd) {
size_t compressed_size = offsets.end - offsets.start;
size_t size = ZSTD_decompress(&v->front(), v->size(),
r.read_bytes(offsets.start, compressed_size), compressed_size);
if (size != v->size()) {
FATAL() << "zstd decompression failed";
}
#endif
} else {
FATAL() << "Unrecognized compression algorithm";
}
Expand Down

0 comments on commit d0f6d50

Please sign in to comment.