@@ -14,6 +14,12 @@
*/
#include "bthread/context.h"
+
+// When building with ASan, skip the .note.GNU-stack section to avoid
+// link errors about discarded sections.
+#if defined(__SANITIZE_ADDRESS__)
+#define BTHREAD_SKIP_GNU_STACK_NOTE
+#endif
#if defined(BTHREAD_CONTEXT_PLATFORM_windows_i386) && defined(BTHREAD_CONTEXT_COMPILER_gcc)
__asm (
".text\n"
@@ -293,7 +299,9 @@ __asm (
" movl %eax, 0x4(%esp)\n"
" jmp *%edx\n"
".size bthread_jump_fcontext,.-bthread_jump_fcontext\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
".previous\n"
);
@@ -328,7 +336,9 @@ __asm (
" call _exit@PLT\n"
" hlt\n"
".size bthread_make_fcontext,.-bthread_make_fcontext\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
".previous\n"
);
@@ -372,7 +382,9 @@ __asm (
" movq %rdx, %rdi\n"
" jmp *%r8\n"
".size bthread_jump_fcontext,.-bthread_jump_fcontext\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
".previous\n"
);
@@ -399,7 +411,9 @@ __asm (
" call _exit@PLT\n"
" hlt\n"
".size bthread_make_fcontext,.-bthread_make_fcontext\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
".previous\n"
);
@@ -575,7 +589,9 @@ __asm (
" pop {pc}\n"
".size bthread_jump_fcontext,.-bthread_jump_fcontext\n"
"@ Mark that we don't need executable stack.\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
);
#endif
@@ -606,7 +622,9 @@ __asm (
" bl _exit@PLT\n"
".size bthread_make_fcontext,.-bthread_make_fcontext\n"
"@ Mark that we don't need executable stack.\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
);
#endif
@@ -677,7 +695,9 @@ __asm (
" ret x4\n"
".size bthread_jump_fcontext,.-bthread_jump_fcontext\n"
"# Mark that we don't need executable stack.\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
);
#endif
@@ -709,7 +729,9 @@ __asm (
" bl _exit\n"
".size bthread_make_fcontext,.-bthread_make_fcontext\n"
"# Mark that we don't need executable stack.\n"
+#if !defined(BTHREAD_SKIP_GNU_STACK_NOTE)
".section .note.GNU-stack,\"\",%progbits\n"
+#endif
);
#endif