在Archlinux中如何使用gcc 7.2编译gcc 6.4.0

10

我正在尝试使用Archlinux中的gcc 7.2独立编译gcc 6.4.0。

具体配置如下:

../configure --prefix=${INSTALL_PREFIX} --enable-languages=c,c++,fortran \
    --enable-threads=posix --enable-tls --enable-libgomp --enable-lto \
    --enable-shared --enable-static --disable-nls --disable-multilib \
    --with-fpmath=sse

编译时,我在md-unwind-support.h中遇到了以下错误:

md-unwind-support.h:65:47: error: dereferencing pointer to incomplete type 'struct ucontext'

我比较了gcc 6.4.0和gcc 7.2.0中定义的md-unwind-support.h,发现在gcc 7.2.0中将struct ucontext定义为ucontext_t。因此,我对gcc 6.4.0源码树中的md-unwind-support.h进行了一些更改,但遇到了一些命名空间问题,如下所示:
int std::uncaught_exceptions() should have been declared inside 'std'

我遇到了问题,对此毫无头绪。

任何帮助和建议都将是有益的。


1
注意:这个问题与使用GCC 7.2没有关系,而是由您的Arch系统使用的最近版本的glibc引起的。 Glibc头文件停止声明非标准名称“struct ucontext”,现在只使用POSIX所需的“ucontext_t” typedef。您可以使用不同版本的GCC,仍然会收到相同的错误。 - Jonathan Wakely
@JonathanWakely 谢谢你的留言。 - Seong
3个回答

12
为了让 make 命令工作,您需要修改文件 make_folder/libgcc/config/i386/linux_unwind.h,其中 make_folder 是您输入 make 命令的文件夹。
linux_unwind.h 文件中,您需要将第 61 行的 struct ucontext *uc_ = context->cfa; 改为 struct ucontext_t *uc_ = context->cfa;
感谢 Seong 告诉我们要修改哪个文件。

还需要在第141行做出另一个更改,以及第61行的更改,请参见https://gcc.gnu.org/viewcvs/gcc/trunk/libgcc/config/i386/linux-unwind.h?r1=249731&r2=249730&pathrev=249731。 - Jonathan Wakely

10
以下是我所做的补丁的摘要。简而言之,将struct ucontext更改为ucontext_t,将struct sigaltstack指针更改为void指针,将struct sigaltstack更改为stack_t。
diff -urN gcc-6.3.0/libgcc/config/i386/linux-unwind.h gcc-6.3.0.new/libgcc/config/i386/linux-unwind.h
--- gcc-6.3.0/libgcc/config/i386/linux-unwind.h 2016-01-04 23:30:50.000000000 +0900
+++ gcc-6.3.0.new/libgcc/config/i386/linux-unwind.h 2017-10-29 23:01:21.717240052 +0900
@@ -58,7 +58,7 @@
   if (*(unsigned char *)(pc+0) == 0x48
       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
     {
-      struct ucontext *uc_ = context->cfa;
+      ucontext_t *uc_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem
          because it does not alias anything.  */
@@ -138,7 +138,7 @@
  siginfo_t *pinfo;
  void *puc;
  siginfo_t info;
- struct ucontext uc;
+ ucontext_t uc;
       } *rt_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem
diff -urN gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_linux.cc
--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc 2015-11-23 18:07:18.000000000 +0900
+++ gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_linux.cc 2017-10-29 23:09:00.490577558 +0900
@@ -546,8 +546,7 @@
 }
 #endif

-uptr internal_sigaltstack(const struct sigaltstack *ss,
-                         struct sigaltstack *oss) {
+uptr internal_sigaltstack(const void *ss, void *oss) {
   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
 }

diff -urN gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_linux.h
--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h 2015-10-21 16:32:45.000000000 +0900
+++ gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_linux.h 2017-10-29 23:09:43.907244619 +0900
@@ -19,7 +19,6 @@
 #include "sanitizer_platform_limits_posix.h"

 struct link_map;  // Opaque type returned by dlopen().
-struct sigaltstack;

 namespace __sanitizer {
 // Dirent structure for getdents(). Note that this structure is different from
@@ -28,8 +27,7 @@

 // Syscall wrappers.
 uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
-uptr internal_sigaltstack(const struct sigaltstack* ss,
-                          struct sigaltstack* oss);
+uptr internal_sigaltstack(const void* ss, void* oss);
 uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
     __sanitizer_sigset_t *oldset);
 void internal_sigfillset(__sanitizer_sigset_t *set);
diff -urN gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc 2015-10-21 16:32:45.000000000 +0900
+++ gcc-6.3.0.new/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc 2017-10-29 23:08:07.260577074 +0900
@@ -267,7 +267,7 @@

   // Alternate stack for signal handling.
   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
-  struct sigaltstack handler_stack;
+  stack_t handler_stack;
   internal_memset(&handler_stack, 0, sizeof(handler_stack));
   handler_stack.ss_sp = handler_stack_memory.data();
   handler_stack.ss_size = kHandlerStackSize;
diff -urN gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc gcc-6.3.0.new/libsanitizer/tsan/tsan_platform_linux.cc
--- gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc 2016-08-12 17:53:46.000000000 +0900
+++ gcc-6.3.0.new/libsanitizer/tsan/tsan_platform_linux.cc 2017-10-29 23:10:38.817245120 +0900
@@ -291,7 +291,7 @@
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
 #if SANITIZER_LINUX
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];

感谢您提供补丁。我确认在进行轻微修改后,它可以与gcc-6.4一起使用。 - Ivan Baidakou

3

我最终解决了这个问题。 我应该修改 libgcc/config/i386/linux_unwind.h 而不是直接修改 md-unwind-support.h


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接