libc/amd64: Do not export .cerror.

For some reason, libc exports the symbol .cerror (HIDENAME(cerror)), albeit
in the FBSDprivate_1.0 version. It looks like there is no reason for this
since it is not used from other libraries. Given that it cannot be accessed
from C and its strange calling convention, it is rather unlikely that other
things rely on it. Perhaps it is from a time when symbols could not be
hidden.

Most of the amd64 assembler code jumps to .cerror using the GOT. It can jump
to it directly now, as in non-PIC mode.

There are also some minor size optimizations to instructions but they yield
virtually no benefit in the size of libc.so.7 due to padding.

Reviewed by:	kib
This commit is contained in:
Jilles Tjoelker 2012-09-06 20:59:49 +00:00
parent 30b5db9fea
commit 5ac7ffcc38
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=240178
12 changed files with 9 additions and 88 deletions

View File

@ -36,38 +36,20 @@
#include <sys/syscall.h>
#include <machine/asm.h>
#ifdef PIC
#define RSYSCALL(x) ENTRY(__CONCAT(__sys_,x)); \
.weak CNAME(x); \
.set CNAME(x),CNAME(__CONCAT(__sys_,x)); \
.weak CNAME(__CONCAT(_,x)); \
.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret; \
2: movq PIC_GOT(HIDENAME(cerror)),%rcx; jmp *%rcx; \
mov __CONCAT($SYS_,x),%eax; KERNCALL; \
jb HIDENAME(cerror); ret; \
END(__CONCAT(__sys_,x))
#define PSEUDO(x) ENTRY(__CONCAT(__sys_,x)); \
.weak CNAME(__CONCAT(_,x)); \
.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret ; \
2: movq PIC_GOT(HIDENAME(cerror)),%rcx; jmp *%rcx; \
mov __CONCAT($SYS_,x),%eax; KERNCALL; \
jb HIDENAME(cerror); ret; \
END(__CONCAT(__sys_,x))
#else
#define RSYSCALL(x) ENTRY(__CONCAT(__sys_,x)); \
.weak CNAME(x); \
.set CNAME(x),CNAME(__CONCAT(__sys_,x)); \
.weak CNAME(__CONCAT(_,x)); \
.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret; \
2: jmp HIDENAME(cerror); \
END(__CONCAT(__sys_,x))
#define PSEUDO(x) ENTRY(__CONCAT(__sys_,x)); \
.weak CNAME(__CONCAT(_,x)); \
.set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \
mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret; \
2: jmp HIDENAME(cerror); \
END(__CONCAT(__sys_,x))
#endif
#define KERNCALL movq %rcx, %r10; syscall

View File

@ -66,7 +66,6 @@ FBSDprivate_1.0 {
.curbrk;
.minbrk;
_brk;
.cerror;
_end;
__sys_vfork;
_vfork;

View File

@ -93,12 +93,7 @@ ENTRY(rfork_thread)
2:
popq %r12
popq %rbx
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)), %rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(rfork_thread)
.section .note.GNU-stack,"",%progbits

View File

@ -76,12 +76,7 @@ ok:
ret
err:
addq $8, %rsp
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(brk)
.section .note.GNU-stack,"",%progbits

View File

@ -47,12 +47,7 @@ ENTRY(exect)
pushq %r8
popfq
KERNCALL
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(exect)
.section .note.GNU-stack,"",%progbits

View File

@ -42,16 +42,9 @@ ENTRY(__sys_getcontext)
movq (%rsp),%rsi /* save getcontext return address */
mov $SYS_getcontext,%rax
KERNCALL
jb 1f
jb HIDENAME(cerror)
addq $8,%rsp /* remove stale (setcontext) return address */
jmp *%rsi /* restore return address */
1:
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(__sys_getcontext)
.section .note.GNU-stack,"",%progbits

View File

@ -45,18 +45,11 @@ __FBSDID("$FreeBSD$");
ENTRY(__sys_pipe)
mov $SYS_pipe,%rax
KERNCALL
jb 1f
jb HIDENAME(cerror)
movl %eax,(%rdi) /* %rdi is preserved by syscall */
movl %edx,4(%rdi)
movq $0,%rax
ret
1:
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(__sys_pipe)
.section .note.GNU-stack,"",%progbits

View File

@ -48,15 +48,8 @@ ENTRY(ptrace)
#endif
mov $SYS_ptrace,%eax
KERNCALL
jb err
jb HIDENAME(cerror)
ret
err:
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(ptrace)
.section .note.GNU-stack,"",%progbits

View File

@ -45,15 +45,8 @@ __FBSDID("$FreeBSD$");
ENTRY(__sys_reboot)
mov $SYS_reboot,%rax
KERNCALL
jb 1f
jb HIDENAME(cerror)
iretq
1:
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(__sys_reboot)
.section .note.GNU-stack,"",%progbits

View File

@ -79,12 +79,7 @@ back:
ret
err:
addq $8, %rsp
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(sbrk)
.section .note.GNU-stack,"",%progbits

View File

@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
ENTRY(__sys_setlogin)
mov $SYS_setlogin,%rax
KERNCALL
jb 1f
jb HIDENAME(cerror)
#ifdef PIC
movq PIC_GOT(CNAME(_logname_valid)),%rdx
movl $0,(%rdx)
@ -55,13 +55,6 @@ ENTRY(__sys_setlogin)
movl $0,CNAME(_logname_valid)(%rip)
#endif
ret /* setlogin(name) */
1:
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(__sys_setlogin)
.section .note.GNU-stack,"",%progbits

View File

@ -50,12 +50,7 @@ ENTRY(__sys_vfork)
jmp *%rsi
1:
pushq %rsi
#ifdef PIC
movq PIC_GOT(HIDENAME(cerror)),%rdx
jmp *%rdx
#else
jmp HIDENAME(cerror)
#endif
END(__sys_vfork)
.section .note.GNU-stack,"",%progbits