Permission denied on go program

2,692 views
Skip to first unread message

Tim Schaeffer

unread,
May 8, 2011, 2:18:06 AM5/8/11
to golan...@googlegroups.com
Hi,

I'm generating the beginnings of a project in go. I have on
program which can build and run successfully.  The second
seems to build successfully, but I get "Permission denied" when
trying to run it.

I have verified that it is a valid executable, the file permissions look correct,


linux:~/workspace$ file test1
test1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), stripped
and strace just tells me that bash couldn't execute the file
(see below). 

I created a small test program with nothing in it but

package main
func main() {
}

Compiling it gives a program with the same problem.  But my first
program still builds and runs fine.

Does anyone have a clue as to what might cause this?  I'm beginning
to suspect that the linker is generating invalid executables, but I don't
know why it would work in one case and not the other.

I'm going to reboot and check my file system just in case it might be screwy (It's a new
installation of Ubuntu and gdm hung my machine a few times, requiring
a Alt-SysReq-b to reboot), but if anyone has seen this before, I'd be glad
to hear a solution, or at least an explanation.

Thanks,
Tim S


$ uname -a
Linux xxxxx-linux 2.6.32-31-generic-pae #61-Ubuntu SMP Fri Apr 8 20:00:13 UTC 2011 i686 GNU/Linux


$ file test1
test1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped


$ stat test1
  File: `test1'
  Size: 1792395       Blocks: 3504       IO Block: 4096   regular file
Device: 805h/2053d    Inode: 25825233    Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/ xxxxx)   Gid: ( 1000/ xxxxx)


$ strace ./test1
execve("./test1", ["./test1"], [/* 32 vars */]) = -1 EACCES (Permission denied)
dup(2)                                  = 3
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fstat64(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fdf000
_llseek(3, 0, 0xbfffe1a8, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
write(3, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
close(3)                                = 0
munmap(0xb7fdf000, 4096)                = 0
exit_group(1)                           = ?


$ objdump -h test1

test1:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .interp       00000002  08048bfe  08048bfe  00000bfe  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .got          00000000  08145000  08145000  000fd000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .got.plt      0000000c  08145098  08145098  000fd098  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  3 .dynsym       00000010  08089004  08089004  00041004  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .dynstr       00000004  08089000  08089000  00041000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .rel.plt      00000000  08089000  08089000  00041000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .plt          00000010  08089014  08089014  00041014  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  7 .hash         00000014  08089024  08089024  00041024  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .rel          00000000  08089000  08089000  00041000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .dynamic      00000070  08089038  08089038  00041038  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 10 .text         0004020f  08048c00  08048c00  00000c00  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 11 .rodata       000bba48  08089000  08089000  00041000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .data         00001d58  08145000  08145000  000fd000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 13 .bss          0040d820  08146d58  08146d58  000fed58  2**2
                  ALLOC
 14 .gosymtab     0007690c  080ce13c  080ce13c  0008613c  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 15 .gopclntab    00005b78  080c85c4  080c85c4  000805c4  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 16 .debug_abbrev 000000cc  00000000  00000000  000ff000  2**0
                  CONTENTS, READONLY, DEBUGGING
 17 .debug_line   0000b858  00000000  00000000  000ff0cc  2**0
                  CONTENTS, READONLY, DEBUGGING
 18 .debug_frame  00006b14  00000000  00000000  0010a924  2**0
                  CONTENTS, READONLY, DEBUGGING
 19 .debug_info   0005e564  00000000  00000000  00111438  2**0
                  CONTENTS, READONLY, DEBUGGING
 20 .debug_pubnames 0002c1aa  00000000  00000000  0016f99c  2**0
                  CONTENTS, READONLY, DEBUGGING
 21 .debug_pubtypes 00019791  00000000  00000000  0019bb46  2**0
                  CONTENTS, READONLY, DEBUGGING
 22 .debug_aranges 00000674  00000000  00000000  001b52d7  2**0
                  CONTENTS, READONLY, DEBUGGING
 23 .debug_gdb_scripts 00000040  00000000  00000000  001b594b  2**0
                  CONTENTS, READONLY, DEBUGGING

bflm

unread,
May 8, 2011, 3:43:21 AM5/8/11
to golang-nuts
On May 8, 8:18 am, Tim Schaeffer <numeroman...@gmail.com> wrote:
> Hi,
>
> I'm generating the beginnings of a project in go. I have on
> program which can build and run successfully.  The second
> seems to build successfully, but I get "Permission denied" when
> trying to run it.
>
> I have verified that it is a valid executable, the file permissions look
> correct,
>
> linux:~/workspace$ file test1
> test1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
> dynamically linked (uses shared libs), stripped

Please try rebuilding your Go program *without* stripping it. I recall
some months ago this helped me to solve a similar mysterious problem
I've got on Linux 64 bit.

Tim Schaeffer

unread,
May 8, 2011, 10:59:32 PM5/8/11
to golan...@googlegroups.com


On Sunday, May 8, 2011 3:43:21 AM UTC-4, bflm wrote:

I missed that clue. But FWIW, I didn't strip these files; they were generated directly
from the linker. There's no flag to the linker to tell it to do this, so I don't know why
they would be created stripped.  This gives me a clue to look at though; thanks.

Tim S.

Dave Cheney

unread,
May 8, 2011, 11:04:15 PM5/8/11
to golan...@googlegroups.com
> I missed that clue. But FWIW, I didn't strip these files; they were
> generated directly
> from the linker. There's no flag to the linker to tell it to do this, so I
> don't know why
> they would be created stripped.  This gives me a clue to look at though;
> thanks.

I think /usr/bin/file doesn't properly understand the format of the
ELF executable, because it can't find the symbols it's looking for, tf
the binary must be stripped.

Are you running anything like AppArmor on that host ? Check syslog to
see if it's decided to step in.

Cheers

Dave

Tim Schaeffer

unread,
May 10, 2011, 10:31:59 AM5/10/11
to golan...@googlegroups.com

Hi,


I have found my problem.  I had copy/modified the compilation command to the linkage command, 
and copied the `-I .' parameter with it.  The `-I' parameter of the compiler is, of course, very different than 
that of the linker.

Sorry for the noise.

Tim S.

Reply all
Reply to author
Forward
0 new messages