Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug/dwarf: support compressed debug sections #11773

Closed
qeedquan opened this issue Jul 18, 2015 · 19 comments
Closed

debug/dwarf: support compressed debug sections #11773

qeedquan opened this issue Jul 18, 2015 · 19 comments
Milestone

Comments

@qeedquan
Copy link
Contributor

I upgraded to go 1.5 beta2 and get this error when building any cgo libraries
cannot load DWARF output from $WORK/command-line-arguments/_obj//cgo.o: decoding dwarf section info at offset 0x0: too short

even simple programs that just does

package main

// #include <stdio.h>
import "C"

func main() {
    C.puts("test")
}

fails to build for me
Using gcc 4.9.2 on amd64

@qeedquan qeedquan changed the title go 1.5beta2 fails to work with gcc 4.9.2 go 1.5beta2 cgo fails to work with gcc 4.9.2 Jul 18, 2015
@alexbrainman
Copy link
Member

What does "go version" output?

Alex

@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Jul 18, 2015
@ianlancetaylor
Copy link
Contributor

What operating system?

Can you show us the output of "go build -x" for a small failing program?

@ianlancetaylor ianlancetaylor changed the title go 1.5beta2 cgo fails to work with gcc 4.9.2 cmd/cgo: go 1.5beta2 cgo fails to work with gcc 4.9.2 Jul 18, 2015
@qeedquan
Copy link
Contributor Author

go version is "go1.5beta2 linux/amd64"

go build -x test.go (the program above):

WORK=/tmp/go-build438987599
mkdir -p $WORK/command-line-arguments/_obj/
cd /home/qeed
CGO_LDFLAGS="-g" "-O2" ./apps/go/pkg/tool/linux_amd64/cgo -objdir $WORK/command-line-arguments/_obj/ -importpath command-line-arguments -- -I $WORK/command-line-arguments/_obj/ test.go
# command-line-arguments
cannot load DWARF output from $WORK/command-line-arguments/_obj//_cgo_.o: decoding dwarf section info at offset 0x0: too short

@ianlancetaylor
Copy link
Contributor

Thanks. Next step: copy test.go into an empty directory, cd to that directory, and run

CGO_LDFLAGS="-g -O2" go tool cgo -debug-gcc -objdir . -importpath command-line-arguments -- -I . test.go

Please attach the output of that.

Also, do you have GOROOT set in the environment?

@qeedquan
Copy link
Contributor Author

I have GOROOT set, but I also tried to unset it and ran the program, either way it gives me an error
The cgo.o file: http://spark.ofloo.net/~qeed/_cgo_.o

$ gcc -E -dM -xc -m64 -I . - <<EOF
#line 3 "/home/qeed/t/test.go"
 #include <stdio.h>


#include <stddef.h> /* for ptrdiff_t and size_t below */

/* Define intgo when compiling with GCC.  */
typedef ptrdiff_t intgo;

typedef struct { char *p; intgo n; } _GoString_;
typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
_GoString_ GoStringN(char *p, int l);
_GoBytes_ GoBytes(void *p, int n);
char *CString(_GoString_);
void *_CMalloc(size_t);
EOF
#define _IO_CURRENTLY_PUTTING 0x800
#define __DBL_MIN_EXP__ (-1021)
#define _IO_peekc_unlocked(_fp) (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) && __underflow (_fp) == EOF ? EOF : *(unsigned char *) (_fp)->_IO_read_ptr)
#define __UINT_LEAST16_MAX__ 65535
#define __ATOMIC_ACQUIRE 2
#define __FLT_MIN__ 1.17549435082228750797e-38F
#define __GCC_IEC_559_COMPLEX 2
#define _IO_UNITBUF 020000
#define __UINT_LEAST8_TYPE__ unsigned char
#define _T_WCHAR_ 
#define __flexarr []
#define _IO_FLAGS2_USER_WBUF 8
#define __S64_TYPE long int
#define __stub_fchflags 
#define __SQUAD_TYPE long int
#define __INTMAX_C(c) c ## L
#define _BSD_SIZE_T_DEFINED_ 
#define __TIME_T_TYPE __SYSCALL_SLONG_TYPE
#define __CHAR_BIT__ 8
#define __FSWORD_T_TYPE __SYSCALL_SLONG_TYPE
#define _G_HAVE_MREMAP 1
#define __UINT8_MAX__ 255
#define __WINT_MAX__ 4294967295U
#define stderr stderr
#define __GLIBC_PREREQ(maj,min) ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
#define __OFF_T_MATCHES_OFF64_T 1
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 18446744073709551615UL
#define __stub_putmsg 
#define __WCHAR_MAX__ 2147483647
#define __BLKCNT_T_TYPE __SYSCALL_SLONG_TYPE
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L)
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
#define __GCC_IEC_559 2
#define _IO_flockfile(_fp) 
#define _IOFBF 0
#define __FLT_EVAL_METHOD__ 0
#define _IO_USER_LOCK 0x8000
#define _IO_NO_WRITES 8
#define __ASMNAME2(prefix,cname) __STRING (prefix) cname
#define __unix__ 1
#define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE)
#define __stub_setlogin 
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __SYSCALL_WORDSIZE 64
#define __x86_64 1
#define __UINT_FAST64_MAX__ 18446744073709551615UL
#define __SIG_ATOMIC_TYPE__ int
#define __GID_T_TYPE __U32_TYPE
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __attribute_alloc_size__(params) __attribute__ ((__alloc_size__ params))
#define __GNUC_PATCHLEVEL__ 2
#define _IO_pid_t __pid_t
#define __UINT_FAST8_MAX__ 255
#define __LEAF , __leaf__
#define __LDBL_REDIR1(name,proto,alias) name proto
#define __has_include(STR) __has_include__(STR)
#define __size_t 
#define __DEC64_MAX_EXP__ 385
#define _WCHAR_T_DEFINED 
#define __INT8_C(c) c
#define __UINT_LEAST64_MAX__ 18446744073709551615UL
#define _IO_FLAGS2_MMAP 1
#define __always_inline __inline __attribute__ ((__always_inline__))
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define _IOS_BIN 128
#define __fortify_function __extern_always_inline __attribute_artificial__
#define _IO_MAGIC_MASK 0xFFFF0000
#define __UINT_LEAST8_MAX__ 255
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
#define __UINTMAX_TYPE__ long unsigned int
#define __linux 1
#define __DEC32_EPSILON__ 1E-6DF
#define __stub_sigreturn 
#define _BITS_TYPES_H 1
#define _IO_cleanup_region_end(_Doit) 
#define _IO_DONT_CLOSE 0100000
#define __unix 1
#define __UINT32_MAX__ 4294967295U
#define __UID_T_TYPE __U32_TYPE
#define getc(_fp) _IO_getc (_fp)
#define __SIZE_T 
#define __LDBL_MAX_EXP__ 16384
#define _ATFILE_SOURCE 1
#define _IO_ssize_t __ssize_t
#define __WINT_MIN__ 0U
#define __linux__ 1
#define _IOS_OUTPUT 2
#define _SIZE_T_DEFINED_ 
#define __LDBL_REDIR_NTH(name,proto) name proto __THROW
#define __SCHAR_MAX__ 127
#define __USING_NAMESPACE_STD(name) 
#define _IO_UNIFIED_JUMPTABLES 1
#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
#define __KERNEL_STRICT_NAMES 
#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
#define __INT64_C(c) c ## L
#define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
#define __DBL_DIG__ 15
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define _POSIX_SOURCE 1
#define __SIZEOF_INT__ 4
#define __SIZEOF_POINTER__ 8
#define _DEFAULT_SOURCE 1
#define __attribute_used__ __attribute__ ((__used__))
#define _STDIO_USES_IOSTREAM 
#define _IO_IN_BACKUP 0x100
#define __USER_LABEL_PREFIX__ 
#define __GLIBC__ 2
#define __END_DECLS 
#define __CONCAT(x,y) x ## y
#define __STDC_HOSTED__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __SLONG32_TYPE int
#define _IO_LINE_BUF 0x200
#define _IOS_NOCREATE 32
#define __GNU_LIBRARY__ 6
#define _G_BUFSIZ 8192
#define __FLT_EPSILON__ 1.19209289550781250000e-7F
#define _IO_EOF_SEEN 0x10
#define TMP_MAX 238328
#define __SSIZE_T_TYPE __SWORD_TYPE
#define __DEV_T_TYPE __UQUAD_TYPE
#define _IO_SKIPWS 01
#define _IO_SCIENTIFIC 04000
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
#define __nonnull(params) __attribute__ ((__nonnull__ params))
#define __DEC32_MAX__ 9.999999E96DF
#define _IO_SHOWPOS 02000
#define _WCHAR_T_ 
#define _STDDEF_H 
#define __INT32_MAX__ 2147483647
#define __SIZEOF_LONG__ 8
#define _IONBF 2
#define _IO_getc_unlocked(_fp) (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++)
#define __STDC_IEC_559__ 1
#define __STDC_ISO_10646__ 201103L
#define __UINT16_C(c) c
#define _IO_PENDING_OUTPUT_COUNT(_fp) ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
#define __DECIMAL_DIG__ 21
#define __USE_FORTIFY_LEVEL 0
#define __gnu_linux__ 1
#define __attribute_warn_unused_result__ __attribute__ ((__warn_unused_result__))
#define __has_include_next(STR) __has_include_next__(STR)
#define _IO_LEFT 02
#define __LDBL_HAS_QUIET_NAN__ 1
#define __attribute_const__ __attribute__ ((__const__))
#define __THROW __attribute__ ((__nothrow__ __LEAF))
#define L_tmpnam 20
#define ___int_wchar_t_h 
#define _T_PTRDIFF 
#define __GNUC__ 4
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __MMX__ 1
#define L_ctermid 9
#define __OFF64_T_TYPE __SQUAD_TYPE
#define offsetof(TYPE,MEMBER) __builtin_offsetof (TYPE, MEMBER)
#define __FLT_HAS_DENORM__ 1
#define __SIZEOF_LONG_DOUBLE__ 16
#define __LDBL_REDIR1_NTH(name,proto,alias) name proto __THROW
#define SEEK_CUR 1
#define __BIGGEST_ALIGNMENT__ 16
#define __USE_ISOC95 1
#define __USE_ISOC99 1
#define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
#define _IO_uid_t __uid_t
#define _GCC_WCHAR_T 
#define __DBL_MAX__ ((double)1.79769313486231570815e+308L)
#define __INT_FAST32_MAX__ 9223372036854775807L
#define __DBL_HAS_INFINITY__ 1
#define stdin stdin
#define __USE_XOPEN2K 1
#define __DEC32_MIN_EXP__ (-94)
#define __DADDR_T_TYPE __S32_TYPE
#define __END_NAMESPACE_C99 
#define __FD_SETSIZE 1024
#define __attribute_format_strfmon__(a,b) __attribute__ ((__format__ (__strfmon__, a, b)))
#define _IO_MAGIC 0xFBAD0000
#define __INT_FAST16_TYPE__ long int
#define _SIZE_T_DEFINED 
#define _WCHAR_T_DEFINED_ 
#define __USE_POSIX199506 1
#define _FEATURES_H 1
#define __LDBL_HAS_DENORM__ 1
#define __stub_getmsg 
#define _IO_FIXED 010000
#define __stub_fattach 
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __INT_LEAST32_MAX__ 2147483647
#define _IO_UNBUFFERED 2
#define _IO_INTERNAL 010
#define __DEC32_MIN__ 1E-95DF
#define __S32_TYPE int
#define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
#define __DBL_MAX_EXP__ 1024
#define __DEC128_EPSILON__ 1E-33DL
#define __SSE2_MATH__ 1
#define __ATOMIC_HLE_RELEASE 131072
#define __FSFILCNT_T_TYPE __SYSCALL_ULONG_TYPE
#define __PTRDIFF_MAX__ 9223372036854775807L
#define __amd64 1
#define _IO_LINKED 0x80
#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
#define __STDC_NO_THREADS__ 1
#define __USECONDS_T_TYPE __U32_TYPE
#define _IO_DELETE_DONT_CLOSE 0x40
#define __BEGIN_NAMESPACE_STD 
#define __OFF_T_TYPE __SYSCALL_SLONG_TYPE
#define __ATOMIC_HLE_ACQUIRE 65536
#define _T_WCHAR 
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __SIZEOF_SIZE_T__ 8
#define _WCHAR_T 
#define __SIZEOF_WINT_T__ 4
#define __stub_bdflush 
#define __U16_TYPE unsigned short int
#define _STDIO_H 1
#define _PTRDIFF_T 
#define __GCC_HAVE_DWARF2_CFI_ASM 1
#define __GXX_ABI_VERSION 1002
#define __FLT_MIN_EXP__ (-125)
#define __extern_always_inline extern __always_inline
#define __PTRDIFF_T 
#define __INT_FAST64_TYPE__ long int
#define _ANSI_STDDEF_H 
#define __DBL_MIN__ ((double)2.22507385850720138309e-308L)
#define __REDIRECT(name,proto,alias) name proto __asm__ (__ASMNAME (#alias))
#define __LP64__ 1
#define _IO_off64_t __off64_t
#define __MODE_T_TYPE __U32_TYPE
#define __LEAF_ATTR __attribute__ ((__leaf__))
#define __DECIMAL_BID_FORMAT__ 1
#define __RLIM64_T_TYPE __UQUAD_TYPE
#define _IOS_ATEND 4
#define _IO_BOOLALPHA 0200000
#define __DEC128_MIN__ 1E-6143DL
#define __REGISTER_PREFIX__ 
#define __UINT16_MAX__ 65535
#define _IOS_NOREPLACE 64
#define __DBL_HAS_DENORM__ 1
#define _IO_TIED_PUT_GET 0x400
#define __USE_POSIX2 1
#define __UINT8_TYPE__ unsigned char
#define __SLONGWORD_TYPE long int
#define __REDIRECT_LDBL(name,proto,alias) __REDIRECT (name, proto, alias)
#define __NO_INLINE__ 1
#define __warndecl(name,msg) extern void name (void) __attribute__((__warning__ (msg)))
#define __FLT_MANT_DIG__ 24
#define __VERSION__ "4.9.2"
#define __UINT64_C(c) c ## UL
#define _PTRDIFF_T_ 
#define _SYS_CDEFS_H 1
#define _STDC_PREDEF_H 1
#define __INT_WCHAR_T_H 
#define _IO_file_flags _flags
#define __USE_XOPEN2K8 1
#define __STRING(x) #x
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define _T_PTRDIFF_ 
#define __INO_T_TYPE __SYSCALL_ULONG_TYPE
#define __ssize_t_defined 
#define __GNUC_PREREQ(maj,min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#define _SYS_SIZE_T_H 
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE
#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define __SUSECONDS_T_TYPE __SYSCALL_SLONG_TYPE
#define __SIZE_T__ 
#define __stub_gtty 
#define __NLINK_T_TYPE __SYSCALL_ULONG_TYPE
#define _IO_SHOWPOINT 0400
#define __stub_sstk 
#define __wur 
#define __STDC_IEC_559_COMPLEX__ 1
#define _G_HAVE_MMAP 1
#define _IO_OCT 040
#define __INT32_C(c) c
#define __DEC64_EPSILON__ 1E-15DD
#define __ORDER_PDP_ENDIAN__ 3412
#define __DEC128_MIN_EXP__ (-6142)
#define __INT_FAST32_TYPE__ long int
#define _BITS_TYPESIZES_H 1
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __UINT_LEAST16_TYPE__ short unsigned int
#define unix 1
#define __INT16_MAX__ 32767
#define __THROWNL __attribute__ ((__nothrow__))
#define _BSD_SIZE_T_ 
#define __SIZE_TYPE__ long unsigned int
#define __UINT64_MAX__ 18446744073709551615UL
#define __va_arg_pack_len() __builtin_va_arg_pack_len ()
#define __ULONGWORD_TYPE unsigned long int
#define _SIZE_T_DECLARED 
#define _IO_SHOWBASE 0200
#define __INT8_TYPE__ signed char
#define __ELF__ 1
#define __ID_T_TYPE __U32_TYPE
#define __warnattr(msg) __attribute__((__warning__ (msg)))
#define _IO_funlockfile(_fp) 
#define __FLT_RADIX__ 2
#define __INT_LEAST16_TYPE__ short int
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
#define __UINTMAX_C(c) c ## UL
#define _POSIX_C_SOURCE 200809L
#define _G_IO_IO_FILE_VERSION 0x20001
#define __SSE_MATH__ 1
#define __long_double_t long double
#define __k8 1
#define __LDBL_REDIR(name,proto) name proto
#define __SIG_ATOMIC_MAX__ 2147483647
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define _IO_IS_FILEBUF 0x2000
#define __SIZEOF_PTRDIFF_T__ 8
#define SEEK_SET 0
#define _IO_FLAGS2_NOTCANCEL 2
#define __errordecl(name,msg) extern void name (void) __attribute__((__error__ (msg)))
#define __restrict_arr __restrict
#define __attribute_artificial__ __attribute__ ((__artificial__))
#define __USE_MISC 1
#define __UWORD_TYPE unsigned long int
#define __x86_64__ 1
#define _SIZE_T_ 
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define _IO_iconv_t _G_iconv_t
#define _IO_USER_BUF 1
#define _WCHAR_T_H 
#define __INT_FAST16_MAX__ 9223372036854775807L
#define __stub_revoke 
#define _IO_off_t __off_t
#define __UINT_FAST32_MAX__ 18446744073709551615UL
#define __UINT_LEAST64_TYPE__ long unsigned int
#define __U64_TYPE unsigned long int
#define __FLT_HAS_QUIET_NAN__ 1
#define _IO_STDIO_H 
#define __FLT_MAX_10_EXP__ 38
#define __LONG_MAX__ 9223372036854775807L
#define __WCHAR_T__ 
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __FLT_HAS_INFINITY__ 1
#define _BSD_PTRDIFF_T_ 
#define __UINT_FAST16_TYPE__ long unsigned int
#define __bos0(ptr) __builtin_object_size (ptr, 0)
#define __DEC64_MAX__ 9.999999999999999E384DD
#define NULL ((void *)0)
#define __CHAR16_TYPE__ short unsigned int
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __USING_NAMESPACE_C99(name) 
#define _VA_LIST_DEFINED 
#define __BLKSIZE_T_TYPE __SYSCALL_SLONG_TYPE
#define _IO_size_t size_t
#define __INT_LEAST16_MAX__ 32767
#define __stub_lchmod 
#define __DEC64_MANT_DIG__ 16
#define __INT64_MAX__ 9223372036854775807L
#define __UINT_LEAST32_MAX__ 4294967295U
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __INT_LEAST64_TYPE__ long int
#define __INT16_TYPE__ short int
#define __INT_LEAST8_TYPE__ signed char
#define __DEC32_MAX_EXP__ 97
#define __INT_FAST8_MAX__ 127
#define __PMT(args) args
#define __INTPTR_MAX__ 9223372036854775807L
#define _OLD_STDIO_MAGIC 0xFABC0000
#define linux 1
#define _IOS_APPEND 8
#define ____FILE_defined 1
#define _IOLBF 1
#define _IO_UPPERCASE 01000
#define __SSE2__ 1
#define __KEY_T_TYPE __S32_TYPE
#define __WORDSIZE 64
#define __BEGIN_DECLS 
#define __LDBL_MANT_DIG__ 64
#define __DBL_HAS_QUIET_NAN__ 1
#define _IO_BAD_SEEN 0x4000
#define __GNUC_VA_LIST 
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __code_model_small__ 1
#define __RLIM_T_TYPE __SYSCALL_ULONG_TYPE
#define FILENAME_MAX 4096
#define __k8__ 1
#define __INTPTR_TYPE__ long int
#define __UINT16_TYPE__ short unsigned int
#define __WCHAR_TYPE__ int
#define __CLOCKID_T_TYPE __S32_TYPE
#define __SIZEOF_FLOAT__ 4
#define _IOS_TRUNC 16
#define __HAVE_COLUMN 
#define __stub_fdetach 
#define __UINTPTR_MAX__ 18446744073709551615UL
#define __DEC64_MIN_EXP__ (-382)
#define __stub_chflags 
#define putc(_ch,_fp) _IO_putc (_ch, _fp)
#define __UQUAD_TYPE unsigned long int
#define __USE_POSIX 1
#define __INT_FAST64_MAX__ 9223372036854775807L
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define BUFSIZ _IO_BUFSIZ
#define __FLT_DIG__ 6
#define __FSID_T_TYPE struct { int __val[2]; }
#define _WCHAR_T_DECLARED 
#define __UINT_FAST64_TYPE__ long unsigned int
#define _IO_putc_unlocked(_ch,_fp) (_IO_BE ((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end, 0) ? __overflow (_fp, (unsigned char) (_ch)) : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
#define __LDBL_REDIR_DECL(name) 
#define __INT_MAX__ 2147483647
#define __amd64__ 1
#define __S16_TYPE short int
#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
#define _T_SIZE_ 
#define _G_va_list __gnuc_va_list
#define _IOS_INPUT 1
#define __INT64_TYPE__ long int
#define __FLT_MAX_EXP__ 128
#define __ORDER_BIG_ENDIAN__ 4321
#define __ptr_t void *
#define __DBL_MANT_DIG__ 53
#define ___int_size_t_h 
#define __TIMER_T_TYPE void *
#define __INT_LEAST64_MAX__ 9223372036854775807L
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
#define __GLIBC_MINOR__ 21
#define __DEC64_MIN__ 1E-383DD
#define __WINT_TYPE__ unsigned int
#define __UINT_LEAST32_TYPE__ unsigned int
#define __SIZEOF_SHORT__ 2
#define __SSE__ 1
#define __LDBL_MIN_EXP__ (-16381)
#define _IO_va_list __gnuc_va_list
#define stdout stdout
#define __REDIRECT_NTHNL(name,proto,alias) name proto __asm__ (__ASMNAME (#alias)) __THROWNL
#define EOF (-1)
#define __INT_LEAST8_MAX__ 127
#define __extern_inline extern __inline
#define __USE_POSIX199309 1
#define ____mbstate_t_defined 1
#define __SIZEOF_INT128__ 16
#define __BLKCNT64_T_TYPE __SQUAD_TYPE
#define __LDBL_MAX_10_EXP__ 4932
#define __ATOMIC_RELAXED 0
#define __FSBLKCNT_T_TYPE __SYSCALL_ULONG_TYPE
#define __DBL_EPSILON__ ((double)2.22044604925031308085e-16L)
#define __stub_stty 
#define _SIZET_ 
#define _LP64 1
#define __REDIRECT_NTH_LDBL(name,proto,alias) __REDIRECT_NTH (name, proto, alias)
#define __UINT8_C(c) c
#define __INT_LEAST32_TYPE__ int
#define __wchar_t__ 
#define SEEK_END 2
#define __SIZEOF_WCHAR_T__ 4
#define __USE_POSIX_IMPLICITLY 1
#define __UINT64_TYPE__ long unsigned int
#define __REDIRECT_NTH(name,proto,alias) name proto __asm__ (__ASMNAME (#alias)) __THROW
#define _IO_RIGHT 04
#define __END_NAMESPACE_STD 
#define _STDDEF_H_ 
#define __INT_FAST8_TYPE__ signed char
#define __PID_T_TYPE __S32_TYPE
#define P_tmpdir "/tmp"
#define __attribute_pure__ __attribute__ ((__pure__))
#define __WORDSIZE_TIME64_COMPAT32 1
#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
#define _IO_cleanup_region_start(_fct,_fp) 
#define _IO_NO_READS 4
#define _IO_DEC 020
#define __DBL_DECIMAL_DIG__ 17
#define __FXSR__ 1
#define __DEC_EVAL_METHOD__ 2
#define _SIZE_T 
#define _IO_ERR_SEEN 0x20
#define __ULONG32_TYPE unsigned int
#define _G_config_h 1
#define FOPEN_MAX 16
#define _IO_STDIO 040000
#define __off_t_defined 
#define _IO_IS_APPENDING 0x1000
#define _GCC_SIZE_T 
#define __INO64_T_TYPE __UQUAD_TYPE
#define __UINT32_C(c) c ## U
#define __INTMAX_MAX__ 9223372036854775807L
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __size_t__ 
#define _IO_BUFSIZ _G_BUFSIZ
#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
#define __BEGIN_NAMESPACE_C99 
#define __INT8_MAX__ 127
#define __UINT_FAST32_TYPE__ long unsigned int
#define __INO_T_MATCHES_INO64_T 1
#define _IO_fpos_t _G_fpos_t
#define __CHAR32_TYPE__ unsigned int
#define __FLT_MAX__ 3.40282346638528859812e+38F
#define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
#define __INT32_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __FLT_MIN_10_EXP__ (-37)
#define _IO_BE(expr,res) __builtin_expect ((expr), res)
#define __SWORD_TYPE long int
#define __INTMAX_TYPE__ long int
#define __DEC128_MAX_EXP__ 6145
#define _T_SIZE 
#define __va_arg_pack() __builtin_va_arg_pack ()
#define __ATOMIC_CONSUME 1
#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
#define __GNUC_MINOR__ 9
#define __UINTMAX_MAX__ 18446744073709551615UL
#define __DEC32_MANT_DIG__ 7
#define __DBL_MAX_10_EXP__ 308
#define __FILE_defined 1
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
#define __INT16_C(c) c
#define __U32_TYPE unsigned int
#define __STDC__ 1
#define __attribute_malloc__ __attribute__ ((__malloc__))
#define __PTRDIFF_TYPE__ long int
#define __attribute_noinline__ __attribute__ ((__noinline__))
#define _IO_HEX 0100
#define __ATOMIC_SEQ_CST 5
#define __CLOCK_T_TYPE __SYSCALL_SLONG_TYPE
#define _IO_fpos64_t _G_fpos64_t
#define __UINT32_TYPE__ unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
#define __DEC128_MANT_DIG__ 34
#define __LDBL_MIN_10_EXP__ (-4931)
#define __attribute_deprecated__ __attribute__ ((__deprecated__))
#define _IO_wint_t wint_t
#define __SIZEOF_LONG_LONG__ 8
#define __USE_ATFILE 1
#define _GCC_PTRDIFF_T 
#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
#define __LDBL_DIG__ 18
#define __FLT_DECIMAL_DIG__ 9
#define __UINT_FAST16_MAX__ 18446744073709551615UL
#define __GNUC_GNU_INLINE__ 1
#define ___int_ptrdiff_t_h 
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
#define _IO_ftrylockfile(_fp) 
#define __glibc_likely(cond) __builtin_expect ((cond), 1)
#define __UINT_FAST8_TYPE__ unsigned char
#define __P(args) args
#define __ATOMIC_ACQ_REL 4
#define __WCHAR_T 
#define __ATOMIC_RELEASE 3
#define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
$ gcc -w -Wno-error -o./_cgo_.o -gdwarf-2 -c -xc -I . -m64 - <<EOF
#line 3 "/home/qeed/t/test.go"
 #include <stdio.h>


#include <stddef.h> /* for ptrdiff_t and size_t below */

/* Define intgo when compiling with GCC.  */
typedef ptrdiff_t intgo;

typedef struct { char *p; intgo n; } _GoString_;
typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
_GoString_ GoStringN(char *p, int l);
_GoBytes_ GoBytes(void *p, int n);
char *CString(_GoString_);
void *_CMalloc(size_t);
#line 1 "not-declared"
void __cgo_f_1_1(void) { __typeof__(puts) *__cgo_undefined__; }
#line 1 "not-type"
void __cgo_f_1_2(void) { puts *__cgo_undefined__; }
#line 1 "not-const"
void __cgo_f_1_3(void) { enum { __cgo__undefined__ = (puts)*1 }; }
#line 1 "completed"
int __cgo__1 = __cgo__2;
EOF
not-type: In function '__cgo_f_1_2':
not-type:1:32: error: '__cgo_undefined__' undeclared (first use in this function)
not-type:1:32: note: each undeclared identifier is reported only once for each function it appears in
not-const: In function '__cgo_f_1_3':
not-const:1:60: error: invalid operands to binary * (have 'int (*)(const char *)' and 'int')
completed: At top level:
completed:1:16: error: '__cgo__2' undeclared here (not in a function)
$ gcc -w -Wno-error -o./_cgo_.o -gdwarf-2 -c -xc -I . -m64 - <<EOF
#line 3 "/home/qeed/t/test.go"
 #include <stdio.h>


#include <stddef.h> /* for ptrdiff_t and size_t below */

/* Define intgo when compiling with GCC.  */
typedef ptrdiff_t intgo;

typedef struct { char *p; intgo n; } _GoString_;
typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
_GoString_ GoStringN(char *p, int l);
_GoBytes_ GoBytes(void *p, int n);
char *CString(_GoString_);
void *_CMalloc(size_t);
__typeof__(puts) *__cgo__0;
__typeof__(puts) *__cgo__1;
long long __cgodebug_data[] = {
    0,
    0,
    1
};
EOF
cannot load DWARF output from ./_cgo_.o: decoding dwarf section info at offset 0x0: too short

@ianlancetaylor
Copy link
Contributor

You should never set GOROOT in the environment, but I understand that you are saying that this is not the problem here.

Please put this (from the end of the above) into a file x.c:

#line 3 "/home/qeed/t/test.go"
#include <stdio.h>

#include <stddef.h> /* for ptrdiff_t and size_t below */

/* Define intgo when compiling with GCC. */
typedef ptrdiff_t intgo;

typedef struct { char *p; intgo n; } GoString;
typedef struct { char *p; intgo n; intgo c; } GoBytes;
GoString GoString(char *p);
GoString GoStringN(char *p, int l);
GoBytes GoBytes(void *p, int n);
char *CString(GoString);
void *_CMalloc(size_t);
typeof(puts) *cgo__0;
__typeof
(puts) *__cgo__1;
long long __cgodebug_data[] = {
0,
0,
1
};

Then run

gcc -w -Wno-error -o./cgo.o -gdwarf-2 -c -xc -I . -m64 x.c

Then attach the output of

readelf -s --wide ./cgo.o

Thanks.

@qeedquan
Copy link
Contributor Author

I should also say that 1.5beta1 used to work, so there was a commit between then and now that broke it

Symbol table '.symtab' contains 15 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS x.c
2: 0000000000000000 0 SECTION LOCAL DEFAULT 1
3: 0000000000000000 0 SECTION LOCAL DEFAULT 2
4: 0000000000000000 0 SECTION LOCAL DEFAULT 3
5: 0000000000000000 0 SECTION LOCAL DEFAULT 4
6: 0000000000000000 0 SECTION LOCAL DEFAULT 6
7: 0000000000000000 0 SECTION LOCAL DEFAULT 7
8: 0000000000000000 0 SECTION LOCAL DEFAULT 9
9: 0000000000000000 0 SECTION LOCAL DEFAULT 10
10: 0000000000000000 0 SECTION LOCAL DEFAULT 12
11: 0000000000000000 0 SECTION LOCAL DEFAULT 11
12: 0000000000000008 8 OBJECT GLOBAL DEFAULT COM __cgo__0
13: 0000000000000008 8 OBJECT GLOBAL DEFAULT COM __cgo__1
14: 0000000000000000 24 OBJECT GLOBAL DEFAULT 2 __cgodebug_data

@ianlancetaylor
Copy link
Contributor

My apologies, I wrote the wrong thing. I was looking for

readelf -S --wide ./_cgo.o

(upper case -S, not lower case -s).

It's extremely odd that this changed between beta1 and beta2. I can not see any relevant changes in cmd/cgo, cmd/go, debug/elf, debug/dwarf, and I can't think of any other relevant code.

@qeedquan
Copy link
Contributor Author

Hm, I have tried reverting back to 1.4.2 and now it gives me the same error, maybe there is something wrong with my gcc install, though I can't think of anything I did recently that could affect it. I tried with CC=clang and it works for me.

I might have to reinstall some packages, but in the mean time let me paste the readelf output
readelf -S --wide ./cgo.o

There are 16 section headers, starting at offset 0x668:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  1
  [ 2] .data             PROGBITS        0000000000000000 000040 000018 00  WA  0   0 16
  [ 3] .bss              NOBITS          0000000000000000 000058 000000 00  WA  0   0  1
  [ 4] .zdebug_info      PROGBITS        0000000000000000 000058 00007e 00      0   0  1
  [ 5] .rela.zdebug_info RELA            0000000000000000 0003d8 0001e0 18   I 14   4  8
  [ 6] .zdebug_abbrev    PROGBITS        0000000000000000 0000d6 000069 00      0   0  1
  [ 7] .zdebug_aranges   PROGBITS        0000000000000000 00013f 00001f 00      0   0  1
  [ 8] .rela.zdebug_aranges RELA            0000000000000000 0005b8 000018 18   I 14   7  8
  [ 9] .debug_line       PROGBITS        0000000000000000 00015e 000035 00      0   0  1
  [10] .zdebug_str       PROGBITS        0000000000000000 000193 0000a0 01  MS  0   0  1
  [11] .comment          PROGBITS        0000000000000000 000233 000012 01  MS  0   0  1
  [12] .note.GNU-stack   PROGBITS        0000000000000000 000245 000000 00      0   0  1
  [13] .shstrtab         STRTAB          0000000000000000 0005d0 000093 00      0   0  1
  [14] .symtab           SYMTAB          0000000000000000 000248 000168 18     15  12  8
  [15] .strtab           STRTAB          0000000000000000 0003b0 000027 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)


@ianlancetaylor
Copy link
Contributor

Thanks. Your compiler is emitting compressed debug info. The Go packages don't know how to parse that yet. This is done by the assembler, via the --compress-debug-sections option. Something must have changed to cause that to happen by default.

@ianlancetaylor ianlancetaylor changed the title cmd/cgo: go 1.5beta2 cgo fails to work with gcc 4.9.2 debug/dwarf: support compressed debug sections Jul 18, 2015
@ianlancetaylor ianlancetaylor modified the milestones: Go1.6, Go1.5 Jul 18, 2015
@rsc
Copy link
Contributor

rsc commented Nov 5, 2015

/cc @aclements

@aclements
Copy link
Member

@ianlancetaylor, is there a reference for compressed DWARF? The best I was able to find is a few sentences at https://sourceware.org/gdb/wiki/Internals%20Debugging-File-Formats (which may be sufficient).

I presume the relocations must apply to the decompressed sections, even though the section table technically says they apply to the compressed sections? In that case, I think we have to do this in debug/elf before passing the sections to debug/dwarf, simply because debug/elf handles the relocations.

@ianlancetaylor
Copy link
Contributor

That link is the old way. The new way is the SHF_COMPRESSED flag in an ELF section. Search for SHF_COMPRESSED in http://www.sco.com/developers/gabi/latest/ch4.sheader.html .

As you say, relocation offsets apply to the uncompressed data.

@gopherbot
Copy link

CL https://golang.org/cl/17340 mentions this issue.

@aclements
Copy link
Member

That link is the old way. The new way is the SHF_COMPRESSED flag in an ELF section. Search for SHF_COMPRESSED in http://www.sco.com/developers/gabi/latest/ch4.sheader.html .

Okay. Is there a flag to ask gcc 4.8.4/as 2.24/ld 2.24 (gold 1.11?) to generate compressed sections so I can test my implementation? Or do I need a newer toolchain?

@ianlancetaylor
Copy link
Contributor

Looks like you need a newer toolchain. In fact, it looks like you need 2.26, which doesn't exist yet. I can send you an object if you like.

@aclements
Copy link
Member

In fact, it looks like you need 2.26, which doesn't exist yet.

Oh. :)

I can send you an object if you like.

Please do. Both ELF32 and ELF64 if that's possible.

@ianlancetaylor
Copy link
Contributor

Please do. Both ELF32 and ELF64 if that's possible.

Sent by direct e-mail.

@gopherbot
Copy link

CL https://golang.org/cl/17341 mentions this issue.

aclements added a commit that referenced this issue Dec 3, 2015
GCC and LLVM support zlib-compressing DWARF debug sections (and
there's some evidence that this may be happening by default in some
circumstances now).

Add support for reading compressed DWARF sections. Since ELF
relocations apply to the decompressed data, decompression is done
before applying relocations. Since relcations are applied by
debug/elf, decompression must also be handled there.

Note that this is different from compressed ELF sections, which is a
more general mechanism used by very recent versions of GCC.

Updates #11773.

Change-Id: I3f4bf1b04d0802cc1e8fcb7c2a5fcf6c467c5089
Reviewed-on: https://go-review.googlesource.com/17340
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants