aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-05-02 22:32:23 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-05-02 22:32:23 +0000
commitfbf2f198ce23f6859ccad3bf8b751cfa412da235 (patch)
tree97e4f701dcc189bd60d5bae5460119270ced5522
parent746d6ed4ad8118e79eefa8f0d95c0ae5a9c4b9c0 (diff)
downloadgcc-fbf2f198ce23f6859ccad3bf8b751cfa412da235.zip
gcc-fbf2f198ce23f6859ccad3bf8b751cfa412da235.tar.gz
gcc-fbf2f198ce23f6859ccad3bf8b751cfa412da235.tar.bz2
libgo: add type/const references to sysinfo.c
This patch adds explicit references to various types and constants defined by the header files included by sysinfo.c (used to drive the generation of gen-sysinfo.go as part of the libgo build via the GCC "-fdump-go-spec" option). The intent is to enable clients to gather the same info generated by "-fdump-go-spec" by instead reading the generated DWARF from a sysinfo.o object file compiled with "-g". Some compilers (notably clang) try to omit DWARF records for a given type unless there is an explicit use of it in the translation unit; the additional references are to insure that everything we want to see in the DWARF shows up. Reviewed-on: https://go-review.googlesource.com/99063 From-SVN: r259868
-rw-r--r--gcc/go/gofrontend/MERGE2
-rwxr-xr-xlibgo/mksysinfo.sh1
-rw-r--r--libgo/sysinfo.c209
3 files changed, 211 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 09c1047..8de30a1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-24cd2e0542cc227200c3f91b9e0eefaa726cbc1c
+cef3d77a3dc0207454aabdc3ef0e8f9a0ffdf32e
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index 1b40dbe..92ecb47 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -29,6 +29,7 @@ echo 'type _ unsafe.Pointer' >> ${OUT}
# will all have a leading underscore.
grep -v '^// ' gen-sysinfo.go | \
grep -v '^func' | \
+ grep -v '^var' | \
grep -v '^type _timeval ' | \
grep -v '^type _timespec_t ' | \
grep -v '^type _timespec ' | \
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index 884d017..fb11826 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -289,3 +289,212 @@ enum {
epoll_data_offset = offsetof(struct epoll_event, data)
};
#endif
+
+// The following section introduces explicit references to types and
+// constants of interest to support bootstrapping libgo using a
+// compiler that doesn't support -fdump-go-spec (e.g., clang), via
+// DWARF-based tools. This process is made more difficult due to the
+// fact that clang tries hard to omit types/constants from DWARF if it
+// can't find explicit references to them, so here we make sure that
+// key items are mentioned in ways that will force them into the
+// generated DWARF.
+
+#if defined(__clang__)
+
+// Make a reference to a type
+#define TREF(typ) typ typ ## ref
+
+// Make a reference to an opaque type
+#define OTREF(typ) typ *typ ## ref
+
+// Make a reference to a struct tag
+#define SREF(stag) struct stag stag ## ref
+
+// Make a reference to an enum literal
+#define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
+
+//......................................................................
+
+// From dirent.h
+SREF(dirent);
+SREF(dirent64);
+OTREF(DIR);
+
+// From fcntl.h
+SREF(flock);
+SREF(flock64);
+
+// From ffi headers
+SREF(_ffi_type);
+TREF(ffi_cif);
+TREF(ffi_abi);
+TREF(ffi_status);
+EREF(FFI_OK);
+
+// From grp.h
+SREF(group);
+
+#if defined(HAVE_LINUX_FILTER_H)
+// From linux/filter.h
+SREF(sock_filter);
+SREF(sock_fprog);
+#endif
+
+// From linux/if.h
+EREF(IFF_UP);
+
+#if defined(HAVE_LINUX_IF_ADDR_H)
+// From linux/if_addr.h
+SREF(ifaddrmsg);
+EREF(IFA_ADDRESS);
+#endif
+
+#if defined(HAVE_LINUX_RTNETLINK_H)
+// From linux/if_link.h
+EREF(IFLA_ADDRESS);
+#endif
+
+// From in.h, in6.h, icmp6.h
+SREF(ip_mreq);
+SREF(ip_mreqn);
+SREF(ipv6_mreq);
+SREF(ip6_mtuinfo);
+SREF(icmp6_filter);
+SREF(in_pktinfo);
+EREF(IPPROTO_TCP);
+
+#if defined(HAVE_LINUX_RTNETLINK_H)
+// From linux/rtnetlink.h
+SREF(rtgenmsg);
+SREF(rtmsg);
+SREF(ifinfomsg);
+SREF(rtattr);
+SREF(rtnexthop);
+EREF(RTM_BASE);
+EREF(RTN_UNSPEC);
+#endif
+
+// From netdb.h
+SREF(addrinfo);
+
+// From netlink.h
+SREF(nlattr);
+SREF(nlmsgerr);
+
+// From pthread.h and related
+TREF(pthread_attr_t);
+TREF(pthread_t);
+TREF(pthread_mutex_t);
+TREF(pthread_mutexattr_t);
+
+// From pwd.h
+SREF(passwd);
+
+// From signal.h and related
+TREF(sigset_t);
+TREF(siginfo_t);
+TREF(stack_t);
+SREF(sigaction);
+SREF(sigstack);
+EREF(SI_USER);
+EREF(FPE_INTOVF);
+EREF(BUS_ADRALN);
+EREF(SS_ONSTACK);
+EREF(SEGV_MAPERR);
+
+// From stat.h
+SREF(stat64);
+
+// From statfs.h
+SREF(statfs);
+SREF(statfs64);
+
+// From sysinfo.h
+SREF(sysinfo);
+
+// From <sys/epoll.h>
+#if defined(HAVE_SYS_EPOLL_H)
+SREF(epoll_event);
+EREF(EPOLLIN);
+EREF(epoll_data_offset);
+#endif
+
+#if defined(HAVE_SYS_MOUNT_H)
+// From sys/mount.h
+EREF(MS_PRIVATE);
+EREF(MNT_FORCE);
+#endif
+
+#if defined(HAVE_SYS_PTRACE_H)
+// From <sys/ptrace.h>
+SREF(pt_regs);
+EREF(PTRACE_PEEKTEXT);
+#endif
+
+// From sys/resource.h
+SREF(rusage);
+SREF(rlimit64);
+EREF(RLIMIT_NOFILE);
+EREF(PRIO_USER);
+
+// From sys/select.h
+TREF(fd_set);
+
+// From sys/socket.h
+SREF(msghdr);
+SREF(cmsghdr);
+SREF(ucred);
+EREF(MSG_OOB);
+EREF(SCM_RIGHTS);
+EREF(SOCK_RAW);
+EREF(SHUT_RD);
+
+// From sys/time.h and sys/times.h
+SREF(timespec);
+SREF(timeval);
+SREF(itimerval);
+SREF(tms);
+EREF(ITIMER_PROF);
+
+#if defined(HAVE_SYS_TIMEX_H)
+// From sys/timex.h
+SREF(timex);
+#endif
+
+// From sys/types.h
+TREF(pid_t);
+TREF(off_t);
+TREF(loff_t);
+TREF(size_t);
+TREF(ssize_t);
+TREF(mode_t);
+TREF(dev_t);
+TREF(time_t);
+
+// From sys/ucontext.h
+TREF(ucontext_t);
+
+#if defined(HAVE_SYS_USER_H)
+// From sys/user.h
+SREF(user_regs_struct);
+#endif
+
+#if defined(HAVE_SYS_UTSNAME_H)
+// From sys/utsname.h
+SREF(utsname);
+#endif
+
+// From termios.h
+SREF(termios);
+
+// From uio.h
+SREF(iovec);
+
+// From utime.h
+SREF(utimbuf);
+
+// From unistd.h
+EREF(_PC_NAME_MAX);
+EREF(_SC_GETPW_R_SIZE_MAX);
+
+#endif // clang