aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/check/crc64_x86.S
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-02-02 21:19:01 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-02-02 21:19:01 +0200
commit99c1c2abfae2e87f3c17e929783e6d1bb7a3f302 (patch)
treef4a8b3bb49469a1d25853f901ba2a24e3fcf5c8e /src/liblzma/check/crc64_x86.S
parentModify LZMA_API macro so that it works on Windows with (diff)
downloadxz-99c1c2abfae2e87f3c17e929783e6d1bb7a3f302.tar.xz
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.
Diffstat (limited to '')
-rw-r--r--src/liblzma/check/crc64_x86.S82
1 files changed, 72 insertions, 10 deletions
diff --git a/src/liblzma/check/crc64_x86.S b/src/liblzma/check/crc64_x86.S
index 78935e65..abd8f9d4 100644
--- a/src/liblzma/check/crc64_x86.S
+++ b/src/liblzma/check/crc64_x86.S
@@ -37,12 +37,37 @@ init_table(void)
* extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
*/
+/*
+ * On some systems, the functions need to be prefixed. The prefix is
+ * 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)
+
+/*
+ * 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
- .type lzma_crc64, @function
+ .globl LZMA_CRC64
+
+#if !defined(__MACH__) && !defined(_WIN32)
+ .type LZMA_CRC64, @function
+#endif
- .align 16
-lzma_crc64:
+ ALIGN(4, 16)
+LZMA_CRC64:
/*
* Register usage:
* %eax crc LSB
@@ -65,12 +90,27 @@ lzma_crc64:
/*
* Store the address of lzma_crc64_table to %ebx. This is needed to
* 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
-.L_PIC:
- popl %ebx
- addl $_GLOBAL_OFFSET_TABLE_+[.-.L_PIC], %ebx
- movl lzma_crc64_table@GOT(%ebx), %ebx
+#if !defined(PIC) && !defined(__PIC__)
+ /* Not PIC */
+ movl $LZMA_CRC64_TABLE, %ebx
+#elif defined(__MACH__)
+ /* 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. */
notl %eax
@@ -200,7 +240,29 @@ lzma_crc64:
popl %ebx
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