Fix assembler warnings.

clang complains if you define a symbol and _then_ make it weak, rather
than the other way round:

  /tmp/setjmp-c3c977.s:90:1: warning: sigsetjmp changed binding to STB_WEAK
  .weak sigsetjmp;
  ^

Test: treehugger
Change-Id: Iee6b0ea456bb2e92aea810ce45f171caabaa89d2
diff --git a/libc/arch-arm/bionic/__restore.S b/libc/arch-arm/bionic/__restore.S
index 5291743..c79c40a 100644
--- a/libc/arch-arm/bionic/__restore.S
+++ b/libc/arch-arm/bionic/__restore.S
@@ -47,7 +47,7 @@
   .save {r0-r15}
   .pad #32
   nop
-ENTRY_PRIVATE_NO_DWARF(__restore)
+ENTRY_NO_DWARF_PRIVATE(__restore)
   // This function must have exactly this instruction sequence.
   mov r7, #__NR_sigreturn
   swi #0
@@ -57,7 +57,7 @@
   .save {r0-r15}
   .pad #160
   nop
-ENTRY_PRIVATE_NO_DWARF(__restore_rt)
+ENTRY_NO_DWARF_PRIVATE(__restore_rt)
   // This function must have exactly this instruction sequence.
   mov r7, #__NR_rt_sigreturn
   swi #0
diff --git a/libc/arch-arm/bionic/setjmp.S b/libc/arch-arm/bionic/setjmp.S
index 2579143..d3d25d4 100644
--- a/libc/arch-arm/bionic/setjmp.S
+++ b/libc/arch-arm/bionic/setjmp.S
@@ -75,14 +75,12 @@
 #define _JB_CORE_BASE   (_JB_FLOAT_STATE+1)
 #define _JB_CHECKSUM    (_JB_CORE_BASE+10)
 
-ENTRY(setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
   mov r1, #1
   b sigsetjmp
 END(setjmp)
 
-ENTRY(_setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
   mov r1, #0
   b sigsetjmp
 END(_setjmp)
@@ -96,8 +94,7 @@
 .endm
 
 // int sigsetjmp(sigjmp_buf env, int save_signal_mask);
-ENTRY(sigsetjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(sigsetjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
   stmfd sp!, {r0, lr}
   .cfi_def_cfa_offset 8
   .cfi_rel_offset r0, 0
@@ -187,8 +184,7 @@
 END(sigsetjmp)
 
 // void siglongjmp(sigjmp_buf env, int value);
-ENTRY(siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(siglongjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(siglongjmp)
   stmfd sp!, {r0, r1, lr}
   .cfi_def_cfa_offset 12
   .cfi_rel_offset r0, 0
@@ -269,7 +265,5 @@
   bx lr
 END(siglongjmp)
 
-ALIAS_SYMBOL(longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(longjmp)
-ALIAS_SYMBOL(_longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_longjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(longjmp, siglongjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(_longjmp, siglongjmp)
diff --git a/libc/arch-arm/bionic/vfork.S b/libc/arch-arm/bionic/vfork.S
index a964be5..f4d329b 100644
--- a/libc/arch-arm/bionic/vfork.S
+++ b/libc/arch-arm/bionic/vfork.S
@@ -29,8 +29,7 @@
 #include <platform/bionic/tls_defines.h>
 #include <private/bionic_asm.h>
 
-ENTRY(vfork)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(vfork)
     // r3 = &__get_tls()[TLS_SLOT_THREAD_ID]
     mrc     p15, 0, r3, c13, c0, 3
     ldr     r3, [r3, #(TLS_SLOT_THREAD_ID * 4)]
diff --git a/libc/arch-arm64/bionic/setjmp.S b/libc/arch-arm64/bionic/setjmp.S
index d787a56..178c4c8 100644
--- a/libc/arch-arm64/bionic/setjmp.S
+++ b/libc/arch-arm64/bionic/setjmp.S
@@ -95,21 +95,18 @@
   m_mangle_registers \reg, sp_reg=\sp_reg
 .endm
 
-ENTRY(setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
   mov w1, #1
   b sigsetjmp
 END(setjmp)
 
-ENTRY(_setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
   mov w1, #0
   b sigsetjmp
 END(_setjmp)
 
 // int sigsetjmp(sigjmp_buf env, int save_signal_mask);
-ENTRY(sigsetjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(sigsetjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
   paciasp
   .cfi_negate_ra_state
   stp x0, x30, [sp, #-16]!
@@ -185,8 +182,7 @@
 END(sigsetjmp)
 
 // void siglongjmp(sigjmp_buf env, int value);
-ENTRY(siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(siglongjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(siglongjmp)
   // Check the checksum before doing anything.
   m_calculate_checksum x12, x0, x2
   ldr x2, [x0, #(_JB_CHECKSUM * 8)]
@@ -290,9 +286,7 @@
   ret
 END(siglongjmp)
 
-ALIAS_SYMBOL(longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(longjmp)
-ALIAS_SYMBOL(_longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_longjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(longjmp, siglongjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(_longjmp, siglongjmp)
 
 NOTE_GNU_PROPERTY()
diff --git a/libc/arch-arm64/bionic/vfork.S b/libc/arch-arm64/bionic/vfork.S
index 9b19232..addb775 100644
--- a/libc/arch-arm64/bionic/vfork.S
+++ b/libc/arch-arm64/bionic/vfork.S
@@ -32,8 +32,7 @@
 #include <asm/signal.h>
 #include <linux/sched.h>
 
-ENTRY(vfork)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(vfork)
     // x9 = __get_tls()[TLS_SLOT_THREAD_ID]
     mrs     x9, tpidr_el0
     ldr     x9, [x9, #(TLS_SLOT_THREAD_ID * 8)]
diff --git a/libc/arch-riscv64/bionic/setjmp.S b/libc/arch-riscv64/bionic/setjmp.S
index 26f7ec9..81b1e35 100644
--- a/libc/arch-riscv64/bionic/setjmp.S
+++ b/libc/arch-riscv64/bionic/setjmp.S
@@ -107,21 +107,18 @@
   m_mangle_registers \reg, sp_reg=\sp_reg
 .endm
 
-ENTRY(setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
   li a1, 1
   tail sigsetjmp
 END(setjmp)
 
-ENTRY(_setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
   li a1, 0
   tail sigsetjmp
 END(_setjmp)
 
 // int sigsetjmp(sigjmp_buf env, int save_signal_mask);
-ENTRY(sigsetjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(sigsetjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
   addi sp, sp, -24
   sd a0, 0(sp)
   sd a1, 8(sp)
@@ -204,8 +201,7 @@
 END(sigsetjmp)
 
 // void siglongjmp(sigjmp_buf env, int value);
-ENTRY(siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(siglongjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(siglongjmp)
   // Check the checksum before doing anything.
   m_calculate_checksum t0, a0, t1
   ld t1, _JB_CHECKSUM(a0)
@@ -298,7 +294,5 @@
   call __bionic_setjmp_checksum_mismatch
 END(siglongjmp)
 
-ALIAS_SYMBOL(longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(longjmp)
-ALIAS_SYMBOL(_longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_longjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(longjmp, siglongjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(_longjmp, siglongjmp)
diff --git a/libc/arch-x86/bionic/__restore.S b/libc/arch-x86/bionic/__restore.S
index 5977eab..10ab8e5 100644
--- a/libc/arch-x86/bionic/__restore.S
+++ b/libc/arch-x86/bionic/__restore.S
@@ -74,18 +74,18 @@
   .cfi_signal_frame
   RESTORE_GPRS(4)
   nop   // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop.
-ENTRY_PRIVATE_NO_DWARF(__restore)
+ENTRY_NO_DWARF_PRIVATE(__restore)
   popl %eax
   RESTORE_GPRS(0)
   movl $__NR_sigreturn, %eax
   int $0x80
-END(__restore)
+END(__restore)  // Not END_NO_DWARF because we _manually_ set up CFI.
 
   .cfi_startproc
   .cfi_signal_frame
   RESTORE_GPRS(160)
   nop   // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop.
-ENTRY_PRIVATE_NO_DWARF(__restore_rt)
+ENTRY_NO_DWARF_PRIVATE(__restore_rt)
   movl $__NR_rt_sigreturn, %eax
   int $0x80
-END(__restore_rt)
+END(__restore_rt)  // Not END_NO_DWARF because we _manually_ set up CFI.
diff --git a/libc/arch-x86/bionic/setjmp.S b/libc/arch-x86/bionic/setjmp.S
index 1a3eb4b..d22683a 100644
--- a/libc/arch-x86/bionic/setjmp.S
+++ b/libc/arch-x86/bionic/setjmp.S
@@ -64,22 +64,19 @@
   .endr
 .endm
 
-ENTRY(setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
   movl 4(%esp),%ecx
   mov $1,%eax
   jmp .L_sigsetjmp
 END(setjmp)
 
-ENTRY(_setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
   movl 4(%esp),%ecx
   movl $0,%eax
   jmp .L_sigsetjmp
 END(_setjmp)
 
-ENTRY(sigsetjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(sigsetjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
   movl 4(%esp),%ecx
   movl 8(%esp),%eax
 
@@ -135,8 +132,7 @@
   ret
 END(sigsetjmp)
 
-ENTRY(siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(siglongjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(siglongjmp)
   movl 4(%esp),%edx
 
   // Check the checksum before doing anything.
@@ -210,7 +206,5 @@
   call PIC_PLT(__bionic_setjmp_checksum_mismatch)
 END(siglongjmp)
 
-ALIAS_SYMBOL(longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(longjmp)
-ALIAS_SYMBOL(_longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_longjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(longjmp, siglongjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(_longjmp, siglongjmp)
diff --git a/libc/arch-x86/bionic/vfork.S b/libc/arch-x86/bionic/vfork.S
index 231a36e..872d0c2 100644
--- a/libc/arch-x86/bionic/vfork.S
+++ b/libc/arch-x86/bionic/vfork.S
@@ -31,8 +31,7 @@
 
 // This custom code preserves the return address across the system call.
 
-ENTRY(vfork)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(vfork)
   popl    %ecx  // Grab the return address.
   .cfi_adjust_cfa_offset 4
   .cfi_rel_offset ecx, 0
diff --git a/libc/arch-x86_64/bionic/__restore_rt.S b/libc/arch-x86_64/bionic/__restore_rt.S
index f3e4012..98d0ef5 100644
--- a/libc/arch-x86_64/bionic/__restore_rt.S
+++ b/libc/arch-x86_64/bionic/__restore_rt.S
@@ -109,7 +109,7 @@
   // Restoring RSP is unnecessary as the unwinder simply uses the CFA value.
   RESTORE_GPR(RIP)
   nop
-ENTRY_PRIVATE_NO_DWARF(__restore_rt)
+ENTRY_NO_DWARF_PRIVATE(__restore_rt)
   mov $__NR_rt_sigreturn, %rax
   syscall
 END(__restore_rt)
diff --git a/libc/arch-x86_64/bionic/setjmp.S b/libc/arch-x86_64/bionic/setjmp.S
index ba3f05f..11db14b 100644
--- a/libc/arch-x86_64/bionic/setjmp.S
+++ b/libc/arch-x86_64/bionic/setjmp.S
@@ -71,21 +71,18 @@
   .endr
 .endm
 
-ENTRY(setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(setjmp)
   movl $1,%esi
   jmp PIC_PLT(sigsetjmp)
 END(setjmp)
 
-ENTRY(_setjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_setjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(_setjmp)
   movl $0,%esi
   jmp PIC_PLT(sigsetjmp)
 END(_setjmp)
 
 // int sigsetjmp(sigjmp_buf env, int save_signal_mask);
-ENTRY(sigsetjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(sigsetjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(sigsetjmp)
   pushq %rdi
   movq %rsi,%rdi
   call PIC_PLT(__bionic_setjmp_cookie_get)
@@ -137,8 +134,7 @@
 END(sigsetjmp)
 
 // void siglongjmp(sigjmp_buf env, int value);
-ENTRY(siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(siglongjmp)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(siglongjmp)
   movq %rdi,%r12
   pushq %rsi // Push 'value'.
 
@@ -203,7 +199,5 @@
   call PIC_PLT(__bionic_setjmp_checksum_mismatch)
 END(siglongjmp)
 
-ALIAS_SYMBOL(longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(longjmp)
-ALIAS_SYMBOL(_longjmp, siglongjmp)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(_longjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(longjmp, siglongjmp)
+ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(_longjmp, siglongjmp)
diff --git a/libc/arch-x86_64/bionic/vfork.S b/libc/arch-x86_64/bionic/vfork.S
index 8cfcc36..56d7050 100644
--- a/libc/arch-x86_64/bionic/vfork.S
+++ b/libc/arch-x86_64/bionic/vfork.S
@@ -31,8 +31,7 @@
 
 // This custom code preserves the return address across the system call.
 
-ENTRY(vfork)
-__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
+ENTRY_WEAK_FOR_NATIVE_BRIDGE(vfork)
   popq    %rdi  // Grab the return address.
 
   // Set cached_pid_ to 0, vforked_ to 1, and stash the previous value.
diff --git a/libc/private/bionic_asm.h b/libc/private/bionic_asm.h
index f9d85b2..b3b2b47 100644
--- a/libc/private/bionic_asm.h
+++ b/libc/private/bionic_asm.h
@@ -51,44 +51,63 @@
 #include <private/bionic_asm_x86_64.h>
 #endif
 
-#define ENTRY_NO_DWARF(f) \
-    .text; \
-    .globl f; \
-    .balign __bionic_asm_align; \
-    .type f, __bionic_asm_function_type; \
-    f: \
-    __bionic_asm_custom_entry(f); \
+// Starts a normal assembler routine.
+#define ENTRY(__f) __ENTRY_WITH_BINDING(__f, .globl)
 
-#define ENTRY(f) \
-    ENTRY_NO_DWARF(f) \
-    .cfi_startproc \
+// Starts an assembler routine with hidden visibility.
+#define ENTRY_PRIVATE(__f)           \
+  __ENTRY_WITH_BINDING(__f, .globl); \
+  .hidden __f;
 
-#define END_NO_DWARF(f) \
-    .size f, .-f; \
-    __bionic_asm_custom_end(f) \
+// Starts an assembler routine that's weak so native bridges can override it.
+#define ENTRY_WEAK_FOR_NATIVE_BRIDGE(__f) __ENTRY_WITH_BINDING(__f, .weak)
 
-#define END(f) \
-    .cfi_endproc; \
-    END_NO_DWARF(f) \
+// Starts an assembler routine with hidden visibility and no DWARF information.
+// Only used for internal functions passed via sa_restorer.
+// TODO: can't we just delete all those and let the kernel do its thing?
+#define ENTRY_NO_DWARF_PRIVATE(__f) \
+  __ENTRY_NO_DWARF(__f, .globl);    \
+  .hidden __f;
 
-/* Like ENTRY, but with hidden visibility. */
-#define ENTRY_PRIVATE(f) \
-    ENTRY(f); \
-    .hidden f \
+// (Implementation detail.)
+#define __ENTRY_NO_DWARF(__f, __binding) \
+  .text;                                 \
+  __binding __f;                         \
+  .balign __bionic_asm_align;            \
+  .type __f, __bionic_asm_function_type; \
+  __f:                                   \
+  __bionic_asm_custom_entry(__f);
 
-/* Like ENTRY_NO_DWARF, but with hidden visibility. */
-#define ENTRY_PRIVATE_NO_DWARF(f) \
-    ENTRY_NO_DWARF(f); \
-    .hidden f \
+// (Implementation detail.)
+#define __ENTRY_WITH_BINDING(__f, __binding) \
+  __ENTRY_NO_DWARF(__f, __binding);          \
+  .cfi_startproc;
 
-#define __BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(f) \
-    .weak f; \
+// Ends a normal assembler routine.
+#define END(__f) \
+  .cfi_endproc;  \
+  END_NO_DWARF(__f)
 
+// Ends an assembler routine with no DWARF information.
+// Only used for internal functions passed via sa_restorer.
+// TODO: can't we just delete all those and let the kernel do its thing?
+#define END_NO_DWARF(__f) \
+  .size __f, .- __f;      \
+  __bionic_asm_custom_end(__f)
+
+// Creates an alias `alias` for the symbol `original`.
 #define ALIAS_SYMBOL(alias, original) \
-    .globl alias; \
-    .equ alias, original
+  .globl alias;                       \
+  .equ alias, original
 
-#define NOTE_GNU_PROPERTY() \
-    __bionic_asm_custom_note_gnu_section()
+// Creates an alias `alias` for the symbol `original` that's weak so it can be
+// separately overridden by native bridges.
+#define ALIAS_SYMBOL_WEAK_FOR_NATIVE_BRIDGE(alias, original) \
+  .weak alias;                                               \
+  .equ alias, original
 
+// Adds a GNU property ELF note. Important on arm64 to declare PAC/BTI support.
+#define NOTE_GNU_PROPERTY() __bionic_asm_custom_note_gnu_section()
+
+// Gives local labels a more convenient and readable syntax.
 #define L(__label) .L##__label