Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
use sysv abi on windows

nasty kludge for msabi

msys2: force gcc build

clarify the clang situation
  • Loading branch information
kspalaiologos committed Oct 14, 2024
1 parent e8e5d77 commit 6a39365
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 31 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,30 @@ jobs:
run: ./configure CC=clang
- name: Make
run: make all self-check

build-windows-x86_64:
name: Compile (Windows x86_64)
needs: [ dist ]
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
strategy:
fail-fast: false
matrix:
feature: [ enable-x86_64, disable-x86_64 ]
steps:
- name: Download source package artifact
uses: actions/download-artifact@v4
with:
name: xpar-${{ github.sha }}
- uses: msys2/setup-msys2@v2
with:
update: true
install: make gcc nasm tar gzip diffutils
- name: Extract source package
run: tar --strip-components=1 -xf xpar-${{ github.sha }}.tar.gz
- name: Configure
run: ./configure CC=gcc --${{ matrix.feature }}
- name: Make
run: make all self-check
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Consult the man page.

The file format will change until the stable version v1.0 is reached.
Do not use xpar for critical data, do not expect backwards or forwards
compatibility until then. Currently tested only on Zen4 x86_64 Linux.
compatibility until then.

# Development

Expand All @@ -42,6 +42,7 @@ A rough outline of some development-related topics below.
- Write a proper readme, manpages, etc.
- Make sure that this builds on Windows and port over the assembly code.
- Fuzz to find segfaults.
- Apple M1-specific optimizations to CRC32.
- 32- vs 64-bit code: determine if there's any compatibility issues.

Low priority:
Expand All @@ -61,3 +62,7 @@ As it stands:
Code style:
- Two space indent, brace on the same line, middle pointers - `char * p;`.

## Show-stoppers

clang bug (msys2 packages repository ticket 4958) - makes it impossible to
build on x86_64 Windows with clang. Only gcc is supported.
9 changes: 2 additions & 7 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#error "Here, have a nickel kid. Go buy yourself a real computer."
#endif

// This often gets us asprintf.
#define _GNU_SOURCE
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
Expand Down Expand Up @@ -51,11 +53,4 @@ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32;
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32;
typedef size_t sz;

// ============================================================================
// Reed-Solomon code parameters (223 bytes of input, 32 bytes of parity).
// ============================================================================
#define K 223
#define N 255
#define T 32

#endif
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ AC_PROG_MAKE_SET
AC_PROG_CC

AC_CHECK_HEADERS([getopt.h io.h])
AC_CHECK_FUNCS([getopt_long asprintf setmode stat commit isatty fsync mmap CreateFileMappingA])
AC_CHECK_FUNCS([getopt_long asprintf stat _commit _setmode isatty fsync mmap CreateFileMappingA])
AC_DEFINE([XPAR_MINOR], [xpar_version_minor], [Minor version number of xpar])
AC_DEFINE([XPAR_MAJOR], [xpar_version_major], [Major version number of xpar])

Expand All @@ -29,6 +29,7 @@ if test "x$enable_x86_64" = "xyes"; then
AC_DEFINE([XPAR_X86_64], [1], [Enable x86_64 platform specific code.])
AM_CONDITIONAL([XPAR_X86_64], [true])
AX_PROG_NASM
AX_GCC_FUNC_ATTRIBUTE([sysv_abi])
else
AM_CONDITIONAL([XPAR_X86_64], [false])
fi
Expand Down
10 changes: 8 additions & 2 deletions crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ u32 crc32c_tabular(u32 crc, u8 * data, sz length) {
}

#if defined(XPAR_X86_64)
#ifdef HAVE_FUNC_ATTRIBUTE_SYSV_ABI
#define EXTERNAL_ABI __attribute__((sysv_abi))
#else
#define EXTERNAL_ABI
#endif

typedef u32 (*crc32c_func)(u32, u8 *, sz);
extern int crc32c_x86_64_cpuflags(void);
extern u32 crc32c_small_x86_64_sse42(u32, u8 *, sz);
extern EXTERNAL_ABI int crc32c_x86_64_cpuflags(void);
extern EXTERNAL_ABI u32 crc32c_small_x86_64_sse42(u32, u8 *, sz);
#endif

u32 crc32c(u8 * data, sz length) {
Expand Down
7 changes: 7 additions & 0 deletions jmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#include <sys/types.h>
#include <sys/stat.h>

// ============================================================================
// Reed-Solomon code parameters (223 bytes of input, 32 bytes of parity).
// ============================================================================
#define K 223
#define N 255
#define T 32

// ============================================================================
// Implementation of Reed-Solomon codes. Follows the BCH view. Original code
// was written by Phil Karn, KA9Q, in 1999. This is a modified version due to
Expand Down
245 changes: 245 additions & 0 deletions m4/ax_gcc_func_attribute.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
#
# DESCRIPTION
#
# This macro checks if the compiler supports one of GCC's function
# attributes; many other compilers also provide function attributes with
# the same syntax. Compiler warnings are used to detect supported
# attributes as unsupported ones are ignored by default so quieting
# warnings when using this macro will yield false positives.
#
# The ATTRIBUTE parameter holds the name of the attribute to be checked.
#
# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.
#
# The macro caches its result in the ax_cv_have_func_attribute_<attribute>
# variable.
#
# The macro currently supports the following function attributes:
#
# alias
# aligned
# alloc_size
# always_inline
# artificial
# cold
# const
# constructor
# constructor_priority for constructor attribute with priority
# deprecated
# destructor
# dllexport
# dllimport
# error
# externally_visible
# fallthrough
# flatten
# format
# format_arg
# gnu_format
# gnu_inline
# hot
# ifunc
# leaf
# malloc
# noclone
# noinline
# nonnull
# noreturn
# nothrow
# optimize
# pure
# sentinel
# sentinel_position
# unused
# used
# visibility
# warning
# warn_unused_result
# weak
# weakref
#
# Unsupported function attributes will be tested with a prototype
# returning an int and not accepting any arguments and the result of the
# check might be wrong or meaningless so use with care.
#
# LICENSE
#
# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 13

AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([
m4_case([$1],
[alias], [
int foo( void ) { return 0; }
int bar( void ) __attribute__(($1("foo")));
],
[aligned], [
int foo( void ) __attribute__(($1(32)));
],
[alloc_size], [
void *foo(int a) __attribute__(($1(1)));
],
[always_inline], [
inline __attribute__(($1)) int foo( void ) { return 0; }
],
[artificial], [
inline __attribute__(($1)) int foo( void ) { return 0; }
],
[cold], [
int foo( void ) __attribute__(($1));
],
[const], [
int foo( void ) __attribute__(($1));
],
[constructor_priority], [
int foo( void ) __attribute__((__constructor__(65535/2)));
],
[constructor], [
int foo( void ) __attribute__(($1));
],
[deprecated], [
int foo( void ) __attribute__(($1("")));
],
[destructor], [
int foo( void ) __attribute__(($1));
],
[dllexport], [
__attribute__(($1)) int foo( void ) { return 0; }
],
[dllimport], [
int foo( void ) __attribute__(($1));
],
[error], [
int foo( void ) __attribute__(($1("")));
],
[externally_visible], [
int foo( void ) __attribute__(($1));
],
[fallthrough], [
void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }};
],
[flatten], [
int foo( void ) __attribute__(($1));
],
[format], [
int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
],
[gnu_format], [
int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2)));
],
[format_arg], [
char *foo(const char *p) __attribute__(($1(1)));
],
[gnu_inline], [
inline __attribute__(($1)) int foo( void ) { return 0; }
],
[hot], [
int foo( void ) __attribute__(($1));
],
[ifunc], [
int my_foo( void ) { return 0; }
static int (*resolve_foo(void))(void) { return my_foo; }
int foo( void ) __attribute__(($1("resolve_foo")));
],
[leaf], [
__attribute__(($1)) int foo( void ) { return 0; }
],
[malloc], [
void *foo( void ) __attribute__(($1));
],
[noclone], [
int foo( void ) __attribute__(($1));
],
[noinline], [
__attribute__(($1)) int foo( void ) { return 0; }
],
[nonnull], [
int foo(char *p) __attribute__(($1(1)));
],
[noreturn], [
void foo( void ) __attribute__(($1));
],
[nothrow], [
int foo( void ) __attribute__(($1));
],
[optimize], [
__attribute__(($1(3))) int foo( void ) { return 0; }
],
[pure], [
int foo( void ) __attribute__(($1));
],
[sentinel], [
int foo(void *p, ...) __attribute__(($1));
],
[sentinel_position], [
int foo(void *p, ...) __attribute__(($1(1)));
],
[sysv_abi], [
__attribute__(($1)) int foo( int a, int b, int c );
],
[returns_nonnull], [
void *foo( void ) __attribute__(($1));
],
[unused], [
int foo( void ) __attribute__(($1));
],
[used], [
int foo( void ) __attribute__(($1));
],
[visibility], [
int foo_def( void ) __attribute__(($1("default")));
int foo_hid( void ) __attribute__(($1("hidden")));
int foo_int( void ) __attribute__(($1("internal")));
int foo_pro( void ) __attribute__(($1("protected")));
],
[warning], [
int foo( void ) __attribute__(($1("")));
],
[warn_unused_result], [
int foo( void ) __attribute__(($1));
],
[weak], [
int foo( void ) __attribute__(($1));
],
[weakref], [
static int foo( void ) { return 0; }
static int bar( void ) __attribute__(($1("foo")));
],
[
m4_warn([syntax], [Unsupported attribute $1, the test may fail])
int foo( void ) __attribute__(($1));
]
)], [])
],
dnl GCC doesn't exit with an error if an unknown attribute is
dnl provided but only outputs a warning, so accept the attribute
dnl only if no warning were issued.
[AS_IF([grep -- -Wattributes conftest.err],
[AS_VAR_SET([ac_var], [no])],
[AS_VAR_SET([ac_var], [yes])])],
[AS_VAR_SET([ac_var], [no])])
])
AS_IF([test yes = AS_VAR_GET([ac_var])],
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
[Define to 1 if the system has the `$1' function attribute])], [])
AS_VAR_POPDEF([ac_var])
])
Loading

0 comments on commit 6a39365

Please sign in to comment.