From d2ef321a59c8121f97c30155bd38e06a9eb441e7 Mon Sep 17 00:00:00 2001 From: Andreas Tobler Date: Thu, 21 Nov 2013 21:25:58 +0000 Subject: [PATCH] Introduce a WEAK_REFERENCE() alias and use it. Get rid of the CNAME and the CONCAT macros in SYS.h. Reviewed by: bde, kib --- lib/libc/amd64/SYS.h | 23 ++++++++++------------- lib/libc/amd64/gen/_setjmp.S | 3 +-- lib/libc/amd64/gen/setjmp.S | 3 +-- lib/libc/amd64/gen/sigsetjmp.S | 3 +-- lib/libc/amd64/sys/getcontext.S | 6 ++---- lib/libc/amd64/sys/pipe.S | 6 ++---- lib/libc/amd64/sys/reboot.S | 6 ++---- lib/libc/amd64/sys/setlogin.S | 6 ++---- lib/libc/amd64/sys/vfork.S | 6 ++---- sys/amd64/include/asm.h | 9 +++++++++ 10 files changed, 32 insertions(+), 39 deletions(-) diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h index a2323839f460..3d9108e062af 100644 --- a/lib/libc/amd64/SYS.h +++ b/lib/libc/amd64/SYS.h @@ -36,20 +36,17 @@ #include #include -#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),%eax; KERNCALL; \ +#define RSYSCALL(name) ENTRY(__sys_##name); \ + WEAK_REFERENCE(__sys_##name, name); \ + WEAK_REFERENCE(__sys_##name, _##name); \ + mov $SYS_##name,%eax; KERNCALL; \ jb HIDENAME(cerror); ret; \ - END(__CONCAT(__sys_,x)) + END(__sys_##name) -#define PSEUDO(x) ENTRY(__CONCAT(__sys_,x)); \ - .weak CNAME(__CONCAT(_,x)); \ - .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ - mov __CONCAT($SYS_,x),%eax; KERNCALL; \ +#define PSEUDO(name) ENTRY(__sys_##name); \ + WEAK_REFERENCE(__sys_##name, _##name); \ + mov $SYS_##name,%eax; KERNCALL; \ jb HIDENAME(cerror); ret; \ - END(__CONCAT(__sys_,x)) + END(__sys_##name) -#define KERNCALL movq %rcx, %r10; syscall +#define KERNCALL movq %rcx, %r10; syscall diff --git a/lib/libc/amd64/gen/_setjmp.S b/lib/libc/amd64/gen/_setjmp.S index 9035632b3776..57079a1d4d86 100644 --- a/lib/libc/amd64/gen/_setjmp.S +++ b/lib/libc/amd64/gen/_setjmp.S @@ -63,8 +63,7 @@ ENTRY(_setjmp) ret END(_setjmp) - .weak CNAME(_longjmp) - .set CNAME(_longjmp),CNAME(___longjmp) + WEAK_REFERENCE(___longjmp, _longjmp) ENTRY(___longjmp) movq %rdi,%rdx /* Restore the mxcsr, but leave exception flags intact. */ diff --git a/lib/libc/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S index 47772be88b7b..c26f52f5b70b 100644 --- a/lib/libc/amd64/gen/setjmp.S +++ b/lib/libc/amd64/gen/setjmp.S @@ -73,8 +73,7 @@ ENTRY(setjmp) ret END(setjmp) - .weak CNAME(longjmp) - .set CNAME(longjmp),CNAME(__longjmp) + WEAK_REFERENCE(__longjmp, longjmp) ENTRY(__longjmp) pushq %rdi pushq %rsi diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S index ef90bc6aa723..02b154ce5fa2 100644 --- a/lib/libc/amd64/gen/sigsetjmp.S +++ b/lib/libc/amd64/gen/sigsetjmp.S @@ -80,8 +80,7 @@ ENTRY(sigsetjmp) ret END(sigsetjmp) - .weak CNAME(siglongjmp) - .set CNAME(siglongjmp),CNAME(__siglongjmp) + WEAK_REFERENCE(__siglongjmp, siglongjmp) ENTRY(__siglongjmp) cmpl $0,88(%rdi) jz 2f diff --git a/lib/libc/amd64/sys/getcontext.S b/lib/libc/amd64/sys/getcontext.S index 112879687dac..b11e65caf580 100644 --- a/lib/libc/amd64/sys/getcontext.S +++ b/lib/libc/amd64/sys/getcontext.S @@ -34,10 +34,8 @@ __FBSDID("$FreeBSD$"); * Otherwise, the setcontext() syscall will return here and we'll * pop off the return address and go to the *setcontext* call. */ - .weak _getcontext - .set _getcontext,__sys_getcontext - .weak getcontext - .set getcontext,__sys_getcontext + WEAK_REFERENCE(__sys_getcontext, _getcontext) + WEAK_REFERENCE(__sys_getcontext, getcontext) ENTRY(__sys_getcontext) movq (%rsp),%rsi /* save getcontext return address */ mov $SYS_getcontext,%rax diff --git a/lib/libc/amd64/sys/pipe.S b/lib/libc/amd64/sys/pipe.S index 8d089db26392..806c9ae2d9e5 100644 --- a/lib/libc/amd64/sys/pipe.S +++ b/lib/libc/amd64/sys/pipe.S @@ -38,10 +38,8 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" - .weak _pipe - .set _pipe,__sys_pipe - .weak pipe - .set pipe,__sys_pipe + WEAK_REFERENCE(__sys_pipe, _pipe) + WEAK_REFERENCE(__sys_pipe, pipe) ENTRY(__sys_pipe) mov $SYS_pipe,%rax KERNCALL diff --git a/lib/libc/amd64/sys/reboot.S b/lib/libc/amd64/sys/reboot.S index fd04ef4b5180..b9ad1c644b4e 100644 --- a/lib/libc/amd64/sys/reboot.S +++ b/lib/libc/amd64/sys/reboot.S @@ -38,10 +38,8 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" - .weak _reboot - .set _reboot,__sys_reboot - .weak reboot - .set reboot,__sys_reboot + WEAK_REFERENCE(__sys_reboot, _reboot) + WEAK_REFERENCE(__sys_reboot, reboot) ENTRY(__sys_reboot) mov $SYS_reboot,%rax KERNCALL diff --git a/lib/libc/amd64/sys/setlogin.S b/lib/libc/amd64/sys/setlogin.S index 73b53641ad73..a0d127de85c2 100644 --- a/lib/libc/amd64/sys/setlogin.S +++ b/lib/libc/amd64/sys/setlogin.S @@ -40,10 +40,8 @@ __FBSDID("$FreeBSD$"); .globl CNAME(_logname_valid) /* in _getlogin() */ - .weak _setlogin - .set _setlogin,__sys_setlogin - .weak setlogin - .set setlogin,__sys_setlogin + WEAK_REFERENCE(__sys_setlogin, _setlogin) + WEAK_REFERENCE(__sys_setlogin, setlogin) ENTRY(__sys_setlogin) mov $SYS_setlogin,%rax KERNCALL diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S index 2afba5830d34..62dc71e83f3e 100644 --- a/lib/libc/amd64/sys/vfork.S +++ b/lib/libc/amd64/sys/vfork.S @@ -38,10 +38,8 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" - .weak _vfork - .set _vfork,__sys_vfork - .weak vfork - .set vfork,__sys_vfork + WEAK_REFERENCE(__sys_vfork, _vfork) + WEAK_REFERENCE(__sys_vfork, vfork) ENTRY(__sys_vfork) popq %rsi /* fetch return address (%rsi preserved) */ mov $SYS_vfork,%rax diff --git a/sys/amd64/include/asm.h b/sys/amd64/include/asm.h index 078da03e5137..87272f76fdde 100644 --- a/sys/amd64/include/asm.h +++ b/sys/amd64/include/asm.h @@ -77,6 +77,15 @@ #endif #define END(x) .size x, . - x +/* + * WEAK_REFERENCE(): create a weak reference alias from sym. + * The macro is not a general asm macro that takes arbitrary names, + * but one that takes only C names. It does the non-null name + * translation inside the macro. + */ +#define WEAK_REFERENCE(sym, alias) \ + .weak CNAME(alias); \ + .equ CNAME(alias),CNAME(sym) #define RCSID(x) .text; .asciz x