Updated the x86 assembler code:
- Use call/ret pair to get instruction pointer for PIC. - Use PIC only if PIC or __PIC__ is #defined. - The code should work on MinGW and Darwin in addition to GNU/Linux and Solaris.
This commit is contained in:
parent
22a0c6dd94
commit
99c1c2abfa
|
@ -307,12 +307,6 @@ if test "x$enable_assembler" = xyes; then
|
||||||
x86_64) enable_assembler=x86_64 ;;
|
x86_64) enable_assembler=x86_64 ;;
|
||||||
*) enable_assembler=no ;;
|
*) enable_assembler=no ;;
|
||||||
esac
|
esac
|
||||||
# Darwin has different ABI than GNU+Linux and Solaris,
|
|
||||||
# and the assembler code doesn't assemble.
|
|
||||||
case $host_os in
|
|
||||||
darwin*) enable_assembler=no ;;
|
|
||||||
*) ;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
case $enable_assembler in
|
case $enable_assembler in
|
||||||
x86)
|
x86)
|
||||||
|
|
|
@ -44,12 +44,37 @@ init_table(void)
|
||||||
* extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
|
* extern uint32_t lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.text
|
/*
|
||||||
.globl lzma_crc32
|
* On some systems, the functions need to be prefixed. The prefix is
|
||||||
.type lzma_crc32, @function
|
* usually an underscore.
|
||||||
|
*/
|
||||||
|
#ifndef __USER_LABEL_PREFIX__
|
||||||
|
# define __USER_LABEL_PREFIX__
|
||||||
|
#endif
|
||||||
|
#define MAKE_SYM_CAT(prefix, sym) prefix ## sym
|
||||||
|
#define MAKE_SYM(prefix, sym) MAKE_SYM_CAT(prefix, sym)
|
||||||
|
#define LZMA_CRC32 MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc32)
|
||||||
|
#define LZMA_CRC32_TABLE MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc32_table)
|
||||||
|
|
||||||
.align 16
|
/*
|
||||||
lzma_crc32:
|
* Solaris assembler doesn't have .p2align, and Darwin uses .align
|
||||||
|
* differently than GNU/Linux and Solaris.
|
||||||
|
*/
|
||||||
|
#ifdef __MACH__
|
||||||
|
# define ALIGN(pow2, abs) .align pow2
|
||||||
|
#else
|
||||||
|
# define ALIGN(pow2, abs) .align abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
.text
|
||||||
|
.globl LZMA_CRC32
|
||||||
|
|
||||||
|
#if !defined(__MACH__) && !defined(_WIN32)
|
||||||
|
.type LZMA_CRC32, @function
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ALIGN(4, 16)
|
||||||
|
LZMA_CRC32:
|
||||||
/*
|
/*
|
||||||
* Register usage:
|
* Register usage:
|
||||||
* %eax crc
|
* %eax crc
|
||||||
|
@ -71,17 +96,32 @@ lzma_crc32:
|
||||||
/*
|
/*
|
||||||
* Store the address of lzma_crc32_table to %ebx. This is needed to
|
* Store the address of lzma_crc32_table to %ebx. This is needed to
|
||||||
* get position-independent code (PIC).
|
* get position-independent code (PIC).
|
||||||
|
*
|
||||||
|
* The PIC macro is defined by libtool, while __PIC__ is defined
|
||||||
|
* by GCC but only on some systems. Testing for both makes it simpler
|
||||||
|
* to test this code without libtool, and keeps the code working also
|
||||||
|
* when built with libtool but using something else than GCC.
|
||||||
*/
|
*/
|
||||||
call .L_PIC
|
#if !defined(PIC) && !defined(__PIC__)
|
||||||
.L_PIC:
|
/* Not PIC */
|
||||||
popl %ebx
|
movl $LZMA_CRC32_TABLE, %ebx
|
||||||
addl $_GLOBAL_OFFSET_TABLE_+[.-.L_PIC], %ebx
|
#elif defined(__MACH__)
|
||||||
movl lzma_crc32_table@GOT(%ebx), %ebx
|
/* Mach-O */
|
||||||
|
call .L_get_pc
|
||||||
|
.L_pic:
|
||||||
|
leal .L_lzma_crc32_table$non_lazy_ptr-.L_pic(%ebx), %ebx
|
||||||
|
movl (%ebx), %ebx
|
||||||
|
#else
|
||||||
|
/* ELF */
|
||||||
|
call .L_get_pc
|
||||||
|
addl $_GLOBAL_OFFSET_TABLE_, %ebx
|
||||||
|
movl LZMA_CRC32_TABLE@GOT(%ebx), %ebx
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Complement the initial value. */
|
/* Complement the initial value. */
|
||||||
notl %eax
|
notl %eax
|
||||||
|
|
||||||
.align 16
|
ALIGN(4, 16)
|
||||||
.L_align:
|
.L_align:
|
||||||
/*
|
/*
|
||||||
* Check if there is enough input to use slicing-by-eight.
|
* Check if there is enough input to use slicing-by-eight.
|
||||||
|
@ -104,7 +144,7 @@ lzma_crc32:
|
||||||
decl %edi
|
decl %edi
|
||||||
jmp .L_align
|
jmp .L_align
|
||||||
|
|
||||||
.align 4
|
ALIGN(2, 4)
|
||||||
.L_slice:
|
.L_slice:
|
||||||
/*
|
/*
|
||||||
* If we get here, there's at least 16 bytes of aligned input
|
* If we get here, there's at least 16 bytes of aligned input
|
||||||
|
@ -214,7 +254,27 @@ lzma_crc32:
|
||||||
popl %ebx
|
popl %ebx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.size lzma_crc32, .-lzma_crc32
|
#if defined(PIC) || defined(__PIC__)
|
||||||
|
ALIGN(4, 16)
|
||||||
|
.L_get_pc:
|
||||||
|
movl (%esp), %ebx
|
||||||
|
ret
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__MACH__) && (defined(PIC) || defined(__PIC__))
|
||||||
|
.section __IMPORT,__pointers,non_lazy_symbol_pointers
|
||||||
|
.L_lzma_crc32_table$non_lazy_ptr:
|
||||||
|
.indirect_symbol LZMA_CRC32_TABLE
|
||||||
|
.long 0
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
/* This is equivalent of __declspec(dllexport). */
|
||||||
|
.section .drectve
|
||||||
|
.ascii " -export:lzma_crc32"
|
||||||
|
|
||||||
|
#else
|
||||||
|
.size LZMA_CRC32, .-LZMA_CRC32
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is needed to support non-executable stack. It's ugly to
|
* This is needed to support non-executable stack. It's ugly to
|
||||||
|
|
|
@ -37,12 +37,37 @@ init_table(void)
|
||||||
* extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
|
* extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.text
|
/*
|
||||||
.globl lzma_crc64
|
* On some systems, the functions need to be prefixed. The prefix is
|
||||||
.type lzma_crc64, @function
|
* usually an underscore.
|
||||||
|
*/
|
||||||
|
#ifndef __USER_LABEL_PREFIX__
|
||||||
|
# define __USER_LABEL_PREFIX__
|
||||||
|
#endif
|
||||||
|
#define MAKE_SYM_CAT(prefix, sym) prefix ## sym
|
||||||
|
#define MAKE_SYM(prefix, sym) MAKE_SYM_CAT(prefix, sym)
|
||||||
|
#define LZMA_CRC64 MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc64)
|
||||||
|
#define LZMA_CRC64_TABLE MAKE_SYM(__USER_LABEL_PREFIX__, lzma_crc64_table)
|
||||||
|
|
||||||
.align 16
|
/*
|
||||||
lzma_crc64:
|
* Solaris assembler doesn't have .p2align, and Darwin uses .align
|
||||||
|
* differently than GNU/Linux and Solaris.
|
||||||
|
*/
|
||||||
|
#ifdef __MACH__
|
||||||
|
# define ALIGN(pow2, abs) .align pow2
|
||||||
|
#else
|
||||||
|
# define ALIGN(pow2, abs) .align abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
.text
|
||||||
|
.globl LZMA_CRC64
|
||||||
|
|
||||||
|
#if !defined(__MACH__) && !defined(_WIN32)
|
||||||
|
.type LZMA_CRC64, @function
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ALIGN(4, 16)
|
||||||
|
LZMA_CRC64:
|
||||||
/*
|
/*
|
||||||
* Register usage:
|
* Register usage:
|
||||||
* %eax crc LSB
|
* %eax crc LSB
|
||||||
|
@ -65,12 +90,27 @@ lzma_crc64:
|
||||||
/*
|
/*
|
||||||
* Store the address of lzma_crc64_table to %ebx. This is needed to
|
* Store the address of lzma_crc64_table to %ebx. This is needed to
|
||||||
* get position-independent code (PIC).
|
* get position-independent code (PIC).
|
||||||
|
*
|
||||||
|
* The PIC macro is defined by libtool, while __PIC__ is defined
|
||||||
|
* by GCC but only on some systems. Testing for both makes it simpler
|
||||||
|
* to test this code without libtool, and keeps the code working also
|
||||||
|
* when built with libtool but using something else than GCC.
|
||||||
*/
|
*/
|
||||||
call .L_PIC
|
#if !defined(PIC) && !defined(__PIC__)
|
||||||
.L_PIC:
|
/* Not PIC */
|
||||||
popl %ebx
|
movl $LZMA_CRC64_TABLE, %ebx
|
||||||
addl $_GLOBAL_OFFSET_TABLE_+[.-.L_PIC], %ebx
|
#elif defined(__MACH__)
|
||||||
movl lzma_crc64_table@GOT(%ebx), %ebx
|
/* Mach-O */
|
||||||
|
call .L_get_pc
|
||||||
|
.L_pic:
|
||||||
|
leal .L_lzma_crc64_table$non_lazy_ptr-.L_pic(%ebx), %ebx
|
||||||
|
movl (%ebx), %ebx
|
||||||
|
#else
|
||||||
|
/* ELF */
|
||||||
|
call .L_get_pc
|
||||||
|
addl $_GLOBAL_OFFSET_TABLE_, %ebx
|
||||||
|
movl LZMA_CRC64_TABLE@GOT(%ebx), %ebx
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Complement the initial value. */
|
/* Complement the initial value. */
|
||||||
notl %eax
|
notl %eax
|
||||||
|
@ -200,7 +240,29 @@ lzma_crc64:
|
||||||
popl %ebx
|
popl %ebx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.size lzma_crc64, .-lzma_crc64
|
#if defined(PIC) || defined(__PIC__)
|
||||||
|
ALIGN(4, 16)
|
||||||
|
.L_get_pc:
|
||||||
|
movl (%esp), %ebx
|
||||||
|
ret
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__MACH__) && (defined(PIC) || defined(__PIC__))
|
||||||
|
/* Mach-O PIC */
|
||||||
|
.section __IMPORT,__pointers,non_lazy_symbol_pointers
|
||||||
|
.L_lzma_crc64_table$non_lazy_ptr:
|
||||||
|
.indirect_symbol LZMA_CRC64_TABLE
|
||||||
|
.long 0
|
||||||
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
/* This is equivalent of __declspec(dllexport). */
|
||||||
|
.section .drectve
|
||||||
|
.ascii " -export:lzma_crc64"
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* ELF */
|
||||||
|
.size LZMA_CRC64, .-LZMA_CRC64
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is needed to support non-executable stack. It's ugly to
|
* This is needed to support non-executable stack. It's ugly to
|
||||||
|
|
Loading…
Reference in New Issue