Skip to content

Commit

Permalink
Merge pull request madler#8 from traceon/apple-clang-linker-fix
Browse files Browse the repository at this point in the history
Fix AppleClang linking
  • Loading branch information
kitaisreal authored Apr 20, 2021
2 parents 7f25452 + 403c74d commit 5cc4d23
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions arch/arm/arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

/*
A hack that helps AppleClang linker to see arm_cpu_has_* flags.
A single call to dummy_linker_glue() in the compilation unit that reads
A single call to dummy_linker_glue_y() in the compilation unit that reads
arm_cpu_has_* flags will resolve "undefined symbol" link error.
*/
void dummy_linker_glue();
void dummy_linker_glue_y();

extern int arm_cpu_has_neon;
extern int arm_cpu_has_crc32;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/armfeature.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# include <winapifamily.h>
#endif

Z_INTERNAL void dummy_linker_glue(void) {}
Z_INTERNAL void dummy_linker_glue_y(void) {}

static int arm_has_crc32() {
#if defined(__linux__) && defined(HWCAP2_CRC32)
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# include <cpuid.h>
#endif

Z_INTERNAL void dummy_linker_glue_y(void) {}

Z_INTERNAL int x86_cpu_has_avx2;
Z_INTERNAL int x86_cpu_has_sse2;
Z_INTERNAL int x86_cpu_has_ssse3;
Expand Down
7 changes: 7 additions & 0 deletions arch/x86/x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#ifndef CPU_H_
#define CPU_H_

/*
A hack that helps AppleClang linker to see x86_cpu_has_* flags.
A single call to dummy_linker_glue_y() in the compilation unit that reads
x86_cpu_has_* flags will resolve "undefined symbol" link error.
*/
void dummy_linker_glue_y();

extern int x86_cpu_has_avx2;
extern int x86_cpu_has_sse2;
extern int x86_cpu_has_ssse3;
Expand Down
5 changes: 5 additions & 0 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ Z_INTERNAL void crc_reset(deflate_state *const s) {
}
#endif
s->strm->adler = PREFIX(crc32)(0L, NULL, 0);

#if defined(__APPLE__)
dummy_linker_glue_x();
dummy_linker_glue_y();
#endif
}

Z_INTERNAL void copy_with_crc(PREFIX3(stream) *strm, unsigned char *dst, unsigned long size) {
Expand Down
7 changes: 6 additions & 1 deletion functable.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ extern uint32_t longest_match_unaligned_avx2(deflate_state *const s, Pos cur_mat
#endif
#endif

Z_INTERNAL void dummy_linker_glue_x(void) {}

/* functable init */
Z_INTERNAL struct functable_s functable;

Expand Down Expand Up @@ -288,10 +290,13 @@ static void __attribute__((constructor)) chunkunroll_stub_init() {
functable.chunkunroll = &chunkunroll_avx;
#endif
#ifdef ARM_NEON_CHUNKSET
dummy_linker_glue();
if (arm_cpu_has_neon)
functable.chunkunroll = &chunkunroll_neon;
#endif

#if defined(__APPLE__)
dummy_linker_glue_y();
#endif
}

static void __attribute__((constructor)) chunkmemset_stub_init() {
Expand Down
9 changes: 8 additions & 1 deletion functable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

#include "deflate.h"

/*
A hack that helps AppleClang linker to see functable.
A single call to dummy_linker_glue_x() in the compilation unit that reads
functable will resolve "undefined symbol" link error.
*/
void dummy_linker_glue_x();

struct functable_s {
void (* insert_string) (deflate_state *const s, const uint32_t str, uint32_t count);
Pos (* quick_insert_string)(deflate_state *const s, const uint32_t str);
Expand All @@ -24,6 +31,6 @@ struct functable_s {
uint8_t* (* chunkmemset_safe) (uint8_t *out, unsigned dist, unsigned len, unsigned left);
};

Z_INTERNAL extern struct functable_s functable;
extern struct functable_s functable;

#endif

0 comments on commit 5cc4d23

Please sign in to comment.