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
This commit is contained in:
Ian Lance Taylor 2018-05-02 22:32:23 +00:00
parent 746d6ed4ad
commit fbf2f198ce
3 changed files with 211 additions and 1 deletions

View File

@ -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.

View File

@ -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 ' | \

View File

@ -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