diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-11-19 11:06:00 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-11-22 13:43:22 -0300 |
commit | bc801b3a40f3a9bc8f24f1d0fdc39413874c3172 (patch) | |
tree | 51db36755fec65ea7aa958bfd2799f3136033c89 /setjmp | |
parent | 5c3ece451d46a7d8721311609bfcb6faafacb39e (diff) | |
download | glibc-bc801b3a40f3a9bc8f24f1d0fdc39413874c3172.tar.gz glibc-bc801b3a40f3a9bc8f24f1d0fdc39413874c3172.tar.xz glibc-bc801b3a40f3a9bc8f24f1d0fdc39413874c3172.zip |
setjmp: Replace jmp_buf-macros.h with jmp_buf-macros.sym
It requires less boilerplate code for newer ports. The _Static_assert checks from internal setjmp are moved to its own internal test since setjmp.h is included early by multiple headers (to generate rtld-sizes.sym). The riscv jmp_buf-macros.h check is also redundant, it is already done by riscv configure.ac. Checked with a build for the affected architectures.
Diffstat (limited to 'setjmp')
-rw-r--r-- | setjmp/Makefile | 3 | ||||
-rw-r--r-- | setjmp/jmp_buf-macros.sym | 11 | ||||
-rw-r--r-- | setjmp/tst-setjmp-check.c | 57 |
3 files changed, 71 insertions, 0 deletions
diff --git a/setjmp/Makefile b/setjmp/Makefile index e1ad33c92d..a121892851 100644 --- a/setjmp/Makefile +++ b/setjmp/Makefile @@ -31,7 +31,10 @@ routines := setjmp sigjmp bsd-setjmp bsd-_setjmp \ tests := tst-setjmp jmpbug bug269-setjmp tst-setjmp-fp \ tst-sigsetjmp tst-setjmp-static tests-static := tst-setjmp-static +tests-internal := \ + tst-setjmp-check +gen-as-const-headers += jmp_buf-macros.sym include ../Rules diff --git a/setjmp/jmp_buf-macros.sym b/setjmp/jmp_buf-macros.sym new file mode 100644 index 0000000000..e43958170d --- /dev/null +++ b/setjmp/jmp_buf-macros.sym @@ -0,0 +1,11 @@ +#include <setjmp.h> +#include <stddef.h> + +-- + +JMP_BUF_SIZE sizeof (jmp_buf) +JMP_BUF_ALIGN _Alignof (jmp_buf) +SIGJMP_BUF_SIZE sizeof (sigjmp_buf) +SIGJMP_BUF_ALIGN _Alignof (sigjmp_buf) +MASK_WAS_SAVED_OFFSET offsetof (struct __jmp_buf_tag, __mask_was_saved) +SAVED_MASK_OFFSET offsetof (struct __jmp_buf_tag, __saved_mask) diff --git a/setjmp/tst-setjmp-check.c b/setjmp/tst-setjmp-check.c new file mode 100644 index 0000000000..392346c538 --- /dev/null +++ b/setjmp/tst-setjmp-check.c @@ -0,0 +1,57 @@ +/* Check jmp_buf sizes, alignments and offsets. + Copyright (C) 2021 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, see + <https://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <setjmp.h> +#include <jmp_buf-macros.h> + +#define SJSTR_HELPER(x) #x +#define SJSTR(x) SJSTR_HELPER(x) + +#define TEST_SIZE(type, size) \ + _Static_assert (sizeof (type) == size, \ + "size of " #type " != " \ + SJSTR (size)) +#define TEST_ALIGN(type, align) \ + _Static_assert (__alignof__ (type) == align , \ + "align of " #type " != " \ + SJSTR (align)) +#define TEST_OFFSET(type, member, offset) \ + _Static_assert (offsetof (type, member) == offset, \ + "offset of " #member " field of " #type " != " \ + SJSTR (offset)) + +/* Check if jmp_buf have the expected sizes. */ +TEST_SIZE (jmp_buf, JMP_BUF_SIZE); +TEST_SIZE (sigjmp_buf, SIGJMP_BUF_SIZE); + +/* Check if jmp_buf have the expected alignments. */ +TEST_ALIGN (jmp_buf, JMP_BUF_ALIGN); +TEST_ALIGN (sigjmp_buf, SIGJMP_BUF_ALIGN); + +/* Check if internal fields in jmp_buf have the expected offsets. */ +TEST_OFFSET (struct __jmp_buf_tag, __mask_was_saved, + MASK_WAS_SAVED_OFFSET); +TEST_OFFSET (struct __jmp_buf_tag, __saved_mask, + SAVED_MASK_OFFSET); + +int +main (int argc, char *argv[]) +{ + return 0; +} |