Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit 7562884

Browse files
authored
Merge pull request #4 from fortanix/jb/fix-errors
Enable warnings, enable warnings are erros, fix errors
2 parents 13fad13 + a7e1be7 commit 7562884

8 files changed

+33
-15
lines changed

libunwind/README_RUST_SGX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Initial Fork has been made from 5.0 release of llvm (commit: 6a075b6de4)
1414
* `cd where you want to build libunwind`
1515
* `mkdir build`
1616
* `cd build`
17-
* `cmake -DCMAKE_BUILD_TYPE="RELEASE" -DRUST_SGX=1 -G "Unix Makefiles" -DLLVM_PATH=<path/to/llvm> <path/to/libunwind>`
17+
* `cmake -DCMAKE_BUILD_TYPE="RELEASE" -DRUST_SGX=1 -G "Unix Makefiles" -DLLVM_ENABLE_WARNINGS=1 -DLIBUNWIND_ENABLE_WERROR=1 -DLIBUNWIND_ENABLE_PEDANTIC=0 -DLLVM_PATH=<path/to/llvm> <path/to/libunwind>`
1818
* `-DCMAKE_BUILD_TYPE="RELEASE"` could be removed to enable debug logs of libunwind.
1919

2020
### Build:

libunwind/src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ endif()
4242
if (RUST_SGX)
4343
# Compile Flags
4444
add_definitions(-DRUST_SGX)
45-
add_definitions(-DU_FORTIFY_SOURCE)
46-
add_definitions(-D_FORTIFY_SOURCE=0)
4745
add_definitions(-D__NO_STRING_INLINES)
4846
add_definitions(-D__NO_MATH_INLINES)
4947
add_definitions(-D_LIBUNWIND_IS_BAREMETAL)
48+
# Can't use add_definitions because CMake will reorder these arguments
49+
list(APPEND LIBUNWIND_COMPILE_FLAGS -U_FORTIFY_SOURCE)
50+
list(APPEND LIBUNWIND_COMPILE_FLAGS -D_FORTIFY_SOURCE=0)
51+
5052
list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-stack-protector)
5153
list(APPEND LIBUNWIND_COMPILE_FLAGS -ffreestanding)
5254
list(APPEND LIBUNWIND_COMPILE_FLAGS -fexceptions)

libunwind/src/UnwindLevel1-gcc-ext.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
14+
1315
#include <inttypes.h>
1416
#include <stdbool.h>
1517
#include <stdint.h>

libunwind/src/UnwindLevel1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
// to export these functions from libunwind.so as well.
2020
#define _LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE 1
2121

22+
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
23+
#pragma GCC diagnostic ignored "-Wempty-body"
24+
2225
#include <inttypes.h>
2326
#include <stdint.h>
2427
#include <stdbool.h>

libunwind/src/UnwindRustSgx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define max_log 256
2222

2323

24-
__attribute__((weak)) struct _IO_FILE *stderr = -1;
24+
__attribute__((weak)) struct _IO_FILE *stderr = (_IO_FILE *)-1;
2525

2626
static int vwrite_err(const char *format, va_list ap)
2727
{
@@ -55,7 +55,7 @@ __attribute__((weak)) int fprintf (FILE *__restrict __stream,
5555
return -1;
5656
} else {
5757
va_list args;
58-
int ret = 0;
58+
ret = 0;
5959
va_start(args, __format);
6060
ret += vwrite_err(__format, args);
6161
va_end(args);
@@ -102,7 +102,7 @@ extern uint64_t TEXT_BASE;
102102
extern uint64_t TEXT_SIZE;
103103
extern uint64_t EH_FRM_HDR_BASE;
104104
extern uint64_t EH_FRM_HDR_SIZE;
105-
extern void IMAGE_BASE;
105+
extern char IMAGE_BASE;
106106

107107
typedef Elf64_Phdr Elf_Phdr;
108108
int
@@ -121,7 +121,7 @@ dl_iterate_phdr (int (*callback) (struct dl_phdr_info *,
121121

122122
memset(pinfo, 0, sizeof(*pinfo));
123123

124-
pinfo->dlpi_addr = &IMAGE_BASE;
124+
pinfo->dlpi_addr = (ElfW(Addr))&IMAGE_BASE;
125125
pinfo->dlpi_phnum = 2;
126126

127127
pinfo->dlpi_phdr = phdr;
@@ -154,7 +154,7 @@ void *libuw_malloc(size_t size)
154154
{
155155
struct libwu_rs_alloc_meta *meta;
156156
size_t alloc_size = size + sizeof(struct libwu_rs_alloc_meta);
157-
meta = (void *)__rust_alloc(alloc_size, sizeof(size_t));
157+
meta = (void *)__rust_c_alloc(alloc_size, sizeof(size_t));
158158
if (!meta) {
159159
return NULL;
160160
}
@@ -169,5 +169,5 @@ void libuw_free(void *p)
169169
return;
170170
}
171171
meta = META_FROM_PTR(p);
172-
__rust_dealloc((unsigned char *)meta, meta->alloc_size, sizeof(size_t));
172+
__rust_c_dealloc((unsigned char *)meta, meta->alloc_size, sizeof(size_t));
173173
}

libunwind/src/UnwindRustSgx.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifdef RUST_SGX
1515

16+
#undef _GNU_SOURCE
1617
#define _GNU_SOURCE
1718
#include <link.h>
1819
#include <stdarg.h>
@@ -70,22 +71,18 @@ extern "C" {
7071
#undef pthread_rwlock_rdlock
7172
#undef pthread_rwlock_wrlock
7273
#undef pthread_rwlock_unlock
74+
#undef PTHREAD_RWLOCK_INITIALIZER
7375

7476
#define pthread_rwlock_t RWLock
75-
#define PTHREAD_RWLOCK_INITIALIZER RWLOCK_INIT
76-
77-
7877
#define pthread_rwlock_rdlock __rust_rwlock_rdlock
7978
#define pthread_rwlock_wrlock __rust_rwlock_wrlock
8079
#define pthread_rwlock_unlock __rust_rwlock_unlock
81-
80+
#define PTHREAD_RWLOCK_INITIALIZER RWLOCK_INIT
8281

8382
#define malloc libuw_malloc
8483
#define free libuw_free
8584

86-
#ifdef dl_iterate_phdr
8785
#undef dl_iterate_phdr
88-
#endif
8986
#define dl_iterate_phdr libuw_dl_iterate_phdr
9087

9188
#ifdef __cplusplus
@@ -96,6 +93,8 @@ void *libuw_malloc(size_t size);
9693

9794
void libuw_free(void *p);
9895

96+
struct dl_phdr_info;
97+
9998
int
10099
libuw_dl_iterate_phdr (int (*callback) (struct dl_phdr_info *,
101100
size_t, void *), void *data);

libunwind/src/UnwindRustSgxSnprintf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* on all source code distributions
66
*/
77

8+
#pragma GCC diagnostic ignored "-Wconversion"
9+
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
10+
#pragma GCC diagnostic ignored "-Wfloat-conversion"
11+
#pragma GCC diagnostic ignored "-Wsign-conversion"
12+
#pragma GCC diagnostic ignored "-Wstrict-overflow"
13+
814
/**************************************************************
915
* Original:
1016
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995

libunwind/src/libunwind.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
14+
#pragma GCC diagnostic ignored "-Wmissing-braces"
15+
#pragma GCC diagnostic ignored "-Wsign-conversion"
16+
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
17+
#pragma GCC diagnostic ignored "-Wstrict-overflow"
18+
1319
#include <libunwind.h>
1420

1521
#ifndef NDEBUG

0 commit comments

Comments
 (0)