This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
PATCH: Add sysdeps/i386/i686/get-pc.S
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 23 Oct 2009 12:15:45 -0700
- Subject: PATCH: Add sysdeps/i386/i686/get-pc.S
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
This patch adds sysdeps/i386/i686/get-pc.S so that we can define
__i686.get_pc_thunk.bx only once. I also changed
sysdeps/i386/i686/memcmp.S to avoid PIC in libc.a.
H.J.
----
2009-10-23 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/i386/i686/get-pc.S: New.
* sysdeps/i386/i686/Makefile (sysdep_routines): Add get-pc.
* sysdeps/i386/i686/memcmp.S (JMPTBL): New.
(BRANCH_TO_JMPTBL_ENTRY): Likewise.
(__i686): Undefine.
(__i686.get_pc_thunk.bx): Removed.
(table_32bytes): Use JMPTBL.
* sysdeps/i386/i686/multiarch/strcspn.S (__i686.get_pc_thunk.bx):
Removed.
* sysdeps/i386/i686/multiarch/strlen.S (__i686.get_pc_thunk.bx):
Likewise.
* sysdeps/i386/i686/multiarch/strspn.S (__i686.get_pc_thunk.bx):
Likewise.
diff --git a/sysdeps/i386/i686/Makefile b/sysdeps/i386/i686/Makefile
index dbcf1c3..30cfbc3 100644
--- a/sysdeps/i386/i686/Makefile
+++ b/sysdeps/i386/i686/Makefile
@@ -7,5 +7,5 @@ endif
stack-align-test-flags += -msse
ifeq ($(subdir),string)
-sysdep_routines += cacheinfo
+sysdep_routines += cacheinfo get-pc
endif
diff --git a/sysdeps/i386/i686/get-pc.S b/sysdeps/i386/i686/get-pc.S
new file mode 100644
index 0000000..5853497
--- /dev/null
+++ b/sysdeps/i386/i686/get-pc.S
@@ -0,0 +1,35 @@
+/* Return PC in a register.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include "asm-syntax.h"
+
+#ifdef SHARED
+/* Work around __i686 defined by gcc. */
+# undef __i686
+
+ .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
+ .globl __i686.get_pc_thunk.bx
+ .hidden __i686.get_pc_thunk.bx
+ ALIGN (4)
+ .type __i686.get_pc_thunk.bx,@function
+__i686.get_pc_thunk.bx:
+ movl (%esp), %ebx
+ ret
+#endif
diff --git a/sysdeps/i386/i686/memcmp.S b/sysdeps/i386/i686/memcmp.S
index 24f6804..bb698b1 100644
--- a/sysdeps/i386/i686/memcmp.S
+++ b/sysdeps/i386/i686/memcmp.S
@@ -22,35 +22,49 @@
#include "bp-sym.h"
#include "bp-asm.h"
-#define PARMS LINKAGE+4 /* Preserve EBX. */
-#define BLK1 PARMS
-#define BLK2 BLK1+PTR_SIZE
-#define LEN BLK2+PTR_SIZE
-#define ENTRANCE pushl %ebx; cfi_adjust_cfa_offset (4); \
+#ifdef SHARED
+# define PARMS LINKAGE+4 /* Preserve EBX. */
+# define ENTRANCE pushl %ebx; cfi_adjust_cfa_offset (4); \
cfi_rel_offset (ebx, 0); ENTER
-#define RETURN popl %ebx; cfi_adjust_cfa_offset (-4); \
+# define RETURN popl %ebx; cfi_adjust_cfa_offset (-4); \
cfi_restore (ebx); LEAVE; ret
+# define JMPTBL(I, B) I - B
+
+/* Work around __i686 defined by gcc. */
+# undef __i686
+
+/* Load an entry in a jump table into EBX and branch to it. TABLE is a
+ jump table with relative offsets. INDEX is a register contains the
+ index into the jump table. */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX) \
+ /* We first load PC into EBX. */ \
+ call __i686.get_pc_thunk.bx; \
+ /* Get the address of the jump table. */ \
+ addl $(TABLE - .), %ebx; \
+ /* Get the entry and convert the relative offset to the \
+ absolute address. */ \
+ addl (%ebx,INDEX,4), %ebx; \
+ addl INDEX, %edx; \
+ addl INDEX, %esi; \
+ jmp *%ebx
+#else
+# define PARMS LINKAGE
+# define ENTRANCE ENTER
+# define RETURN LEAVE; ret
+# define JMPTBL(I, B) I
+
+/* Branch to an entry in a jump table. TABLE is a jump table with
+ absolute offsets. INDEX is a register contains the index into
+ the jump table. */
+# define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX) \
+ addl INDEX, %edx; \
+ addl INDEX, %esi; \
+ jmp *TABLE(,INDEX,4)
+#endif
-/* Load an entry in a jump table into EBX. TABLE is a jump table
- with relative offsets. INDEX is a register contains the index
- into the jump table. */
-#define LOAD_JUMP_TABLE_ENTRY(TABLE, INDEX) \
- /* We first load PC into EBX. */ \
- call __i686.get_pc_thunk.bx; \
- /* Get the address of the jump table. */ \
- addl $(TABLE - .), %ebx; \
- /* Get the entry and convert the relative offset to the \
- absolute address. */ \
- addl (%ebx,INDEX,4), %ebx
-
- .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
- .globl __i686.get_pc_thunk.bx
- .hidden __i686.get_pc_thunk.bx
- ALIGN (4)
- .type __i686.get_pc_thunk.bx,@function
-__i686.get_pc_thunk.bx:
- movl (%esp), %ebx
- ret
+#define BLK1 PARMS
+#define BLK2 BLK1+PTR_SIZE
+#define LEN BLK2+PTR_SIZE
.text
ALIGN (4)
@@ -89,10 +103,7 @@ L(not_1):
cmpl $32, %ecx;
jge L(32bytesormore) /* LEN => 32 */
- LOAD_JUMP_TABLE_ENTRY (L(table_32bytes), %ecx)
- addl %ecx, %edx
- addl %ecx, %esi
- jmp *%ebx
+ BRANCH_TO_JMPTBL_ENTRY (L(table_32bytes), %ecx)
ALIGN (4)
L(28bytes):
@@ -335,10 +346,7 @@ L(32bytesormore):
cmpl $32, %ecx
jge L(32bytesormore)
- LOAD_JUMP_TABLE_ENTRY (L(table_32bytes), %ecx)
- addl %ecx, %edx
- addl %ecx, %esi
- jmp *%ebx
+ BRANCH_TO_JMPTBL_ENTRY (L(table_32bytes), %ecx)
L(load_ecx_28):
addl $0x4, %edx
@@ -381,38 +389,38 @@ END (BP_SYM (memcmp))
.section .rodata
ALIGN (2)
L(table_32bytes) :
- .long L(0bytes) - L(table_32bytes)
- .long L(1bytes) - L(table_32bytes)
- .long L(2bytes) - L(table_32bytes)
- .long L(3bytes) - L(table_32bytes)
- .long L(4bytes) - L(table_32bytes)
- .long L(5bytes) - L(table_32bytes)
- .long L(6bytes) - L(table_32bytes)
- .long L(7bytes) - L(table_32bytes)
- .long L(8bytes) - L(table_32bytes)
- .long L(9bytes) - L(table_32bytes)
- .long L(10bytes) - L(table_32bytes)
- .long L(11bytes) - L(table_32bytes)
- .long L(12bytes) - L(table_32bytes)
- .long L(13bytes) - L(table_32bytes)
- .long L(14bytes) - L(table_32bytes)
- .long L(15bytes) - L(table_32bytes)
- .long L(16bytes) - L(table_32bytes)
- .long L(17bytes) - L(table_32bytes)
- .long L(18bytes) - L(table_32bytes)
- .long L(19bytes) - L(table_32bytes)
- .long L(20bytes) - L(table_32bytes)
- .long L(21bytes) - L(table_32bytes)
- .long L(22bytes) - L(table_32bytes)
- .long L(23bytes) - L(table_32bytes)
- .long L(24bytes) - L(table_32bytes)
- .long L(25bytes) - L(table_32bytes)
- .long L(26bytes) - L(table_32bytes)
- .long L(27bytes) - L(table_32bytes)
- .long L(28bytes) - L(table_32bytes)
- .long L(29bytes) - L(table_32bytes)
- .long L(30bytes) - L(table_32bytes)
- .long L(31bytes) - L(table_32bytes)
+ .long JMPTBL (L(0bytes), L(table_32bytes))
+ .long JMPTBL (L(1bytes), L(table_32bytes))
+ .long JMPTBL (L(2bytes), L(table_32bytes))
+ .long JMPTBL (L(3bytes), L(table_32bytes))
+ .long JMPTBL (L(4bytes), L(table_32bytes))
+ .long JMPTBL (L(5bytes), L(table_32bytes))
+ .long JMPTBL (L(6bytes), L(table_32bytes))
+ .long JMPTBL (L(7bytes), L(table_32bytes))
+ .long JMPTBL (L(8bytes), L(table_32bytes))
+ .long JMPTBL (L(9bytes), L(table_32bytes))
+ .long JMPTBL (L(10bytes), L(table_32bytes))
+ .long JMPTBL (L(11bytes), L(table_32bytes))
+ .long JMPTBL (L(12bytes), L(table_32bytes))
+ .long JMPTBL (L(13bytes), L(table_32bytes))
+ .long JMPTBL (L(14bytes), L(table_32bytes))
+ .long JMPTBL (L(15bytes), L(table_32bytes))
+ .long JMPTBL (L(16bytes), L(table_32bytes))
+ .long JMPTBL (L(17bytes), L(table_32bytes))
+ .long JMPTBL (L(18bytes), L(table_32bytes))
+ .long JMPTBL (L(19bytes), L(table_32bytes))
+ .long JMPTBL (L(20bytes), L(table_32bytes))
+ .long JMPTBL (L(21bytes), L(table_32bytes))
+ .long JMPTBL (L(22bytes), L(table_32bytes))
+ .long JMPTBL (L(23bytes), L(table_32bytes))
+ .long JMPTBL (L(24bytes), L(table_32bytes))
+ .long JMPTBL (L(25bytes), L(table_32bytes))
+ .long JMPTBL (L(26bytes), L(table_32bytes))
+ .long JMPTBL (L(27bytes), L(table_32bytes))
+ .long JMPTBL (L(28bytes), L(table_32bytes))
+ .long JMPTBL (L(29bytes), L(table_32bytes))
+ .long JMPTBL (L(30bytes), L(table_32bytes))
+ .long JMPTBL (L(31bytes), L(table_32bytes))
#undef bcmp
diff --git a/sysdeps/i386/i686/multiarch/strcspn.S b/sysdeps/i386/i686/multiarch/strcspn.S
index 73e7eb4..171be54 100644
--- a/sysdeps/i386/i686/multiarch/strcspn.S
+++ b/sysdeps/i386/i686/multiarch/strcspn.S
@@ -43,15 +43,6 @@
need strpbrk before the initialization happened. */
#if (defined SHARED || !defined USE_AS_STRPBRK) && !defined NOT_IN_libc
# ifdef SHARED
- .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
- .globl __i686.get_pc_thunk.bx
- .hidden __i686.get_pc_thunk.bx
- .p2align 4
- .type __i686.get_pc_thunk.bx,@function
-__i686.get_pc_thunk.bx:
- movl (%esp), %ebx
- ret
-
.text
ENTRY(STRCSPN)
.type STRCSPN, @gnu_indirect_function
diff --git a/sysdeps/i386/i686/multiarch/strlen.S b/sysdeps/i386/i686/multiarch/strlen.S
index 0c1e864..c73bea1 100644
--- a/sysdeps/i386/i686/multiarch/strlen.S
+++ b/sysdeps/i386/i686/multiarch/strlen.S
@@ -25,15 +25,6 @@
DSO. In static binaries, we need strlen before the initialization
happened. */
#if defined SHARED && !defined NOT_IN_libc
- .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
- .globl __i686.get_pc_thunk.bx
- .hidden __i686.get_pc_thunk.bx
- .p2align 4
- .type __i686.get_pc_thunk.bx,@function
-__i686.get_pc_thunk.bx:
- movl (%esp), %ebx
- ret
-
.text
ENTRY(strlen)
.type strlen, @gnu_indirect_function
diff --git a/sysdeps/i386/i686/multiarch/strspn.S b/sysdeps/i386/i686/multiarch/strspn.S
index f306d2d..804ddae 100644
--- a/sysdeps/i386/i686/multiarch/strspn.S
+++ b/sysdeps/i386/i686/multiarch/strspn.S
@@ -28,15 +28,6 @@
/* Define multiple versions only for the definition in libc. */
#ifndef NOT_IN_libc
# ifdef SHARED
- .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
- .globl __i686.get_pc_thunk.bx
- .hidden __i686.get_pc_thunk.bx
- .p2align 4
- .type __i686.get_pc_thunk.bx,@function
-__i686.get_pc_thunk.bx:
- movl (%esp), %ebx
- ret
-
.text
ENTRY(strspn)
.type strspn, @gnu_indirect_function