执行二进制文件时出现“无此文件或目录”错误,还显示权限被拒绝

Shubham
I was just trying to execute a simple program **.c** program on **OPNESUSE-42.1** 
I did the following set of commands in which showing **Permission Denied** and also showing **relocatable** i am not able to understand that how it becomes relocatable file.

$ file datasize.o

datasize.o:可重定位的ELF 64位LSB,x86-64,版本1(SYSV),未剥离

无法执行:-

./datasize.o

bash:./datasize.o:权限被拒绝

即使有ldd

ldd datasize.o

ldd:警告:您没有动态可执行文件`./datasize.o'的执行权限

strace的输出

strace ./datasize.o

execve("./datasize.o", ["./datasize.o"], [/* 87 vars */]) = -1 EACCES (Permission denied)
write(2, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
exit_group(1)                           = ?
+++ exited with 1 +++

readelf的输出:-

readelf -a ./datasize.o 

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          1040 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         13
  Section header string table index: 10

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000000000  00000040
       000000000000009c  0000000000000000  AX       0     0     1
  [ 2] .rela.text        RELA             0000000000000000  00000318
       0000000000000078  0000000000000018   I      11     1     8
  [ 3] .data             PROGBITS         0000000000000000  000000dc
       0000000000000000  0000000000000000  WA       0     0     1
  [ 4] .bss              NOBITS           0000000000000000  000000dc
       0000000000000000  0000000000000000  WA       0     0     1
  [ 5] .rodata           PROGBITS         0000000000000000  000000e0
       0000000000000087  0000000000000000   A       0     0     8
  [ 6] .comment          PROGBITS         0000000000000000  00000167
       0000000000000019  0000000000000001  MS       0     0     1
  [ 7] .note.GNU-stack   PROGBITS         0000000000000000  00000180
       0000000000000000  0000000000000000           0     0     1
  [ 8] .eh_frame         PROGBITS         0000000000000000  00000180
       0000000000000038  0000000000000000   A       0     0     8
  [ 9] .rela.eh_frame    RELA             0000000000000000  00000390
       0000000000000018  0000000000000018   I      11     8     8
  [10] .shstrtab         STRTAB           0000000000000000  000003a8
       0000000000000061  0000000000000000           0     0     1
  [11] .symtab           SYMTAB           0000000000000000  000001b8
       0000000000000138  0000000000000018          12     9     8
  [12] .strtab           STRTAB           0000000000000000  000002f0
       0000000000000023  0000000000000000           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)

There are no section groups in this file.

There are no program headers in this file.

Relocation section '.rela.text' at offset 0x318 contains 5 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000023  000a00000002 R_X86_64_PC32     0000000000000000 uname - 4
000000000028  00050000000a R_X86_64_32       0000000000000000 .rodata + 0
00000000002d  000b00000002 R_X86_64_PC32     0000000000000000 puts - 4
000000000087  00050000000a R_X86_64_32       0000000000000000 .rodata + 48
000000000091  000c00000002 R_X86_64_PC32     0000000000000000 printf - 4

Relocation section '.rela.eh_frame' at offset 0x390 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000020  000200000002 R_X86_64_PC32     0000000000000000 .text + 0

The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.

Symbol table '.symtab' contains 13 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS datasize.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    7 
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    8 
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    6 
     9: 0000000000000000   156 FUNC    GLOBAL DEFAULT    1 main
    10: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND uname
    11: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND puts
    12: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND printf

No version information found in this file.
阿斯塔拉

实际上,如果“ .o”文件不是真正的“ .o”文件,则可以执行它们。即,如果将“ ls”复制到“ ls.o”,则可以执行ls.o,它将为您提供“ ls”命令的输出。顺便说一句,@ jaychris,您可能不想将编译的输出放入“ C”源文件中。可以,但是就像拥有可执行文件“ ls.o”一样,这可能会令人困惑。

在原始发布中,我没有看到用户尝试运行的文件具有“可执行”权限。如果作者可以执行“ \ ls -l datasize.o”,则他们将显示对其具有的权限。

请注意,仅设置可执行位(使用“ chmod + x datasize.o”),就不会使其成为可运行的程序(如果它确实是可链接文件)。在这种情况下,如果datasize.o中包含“ main”,则可以尝试@jaychris暗示的内容...使用gcc -o datasize datasize.c ...不会生成可链接的“ datasize.o” ”,但将尝试创建可执行文件并将其放入名为“ datasize”的文件中(您仍必须使用“ chmod + x datasize”启用“可执行”权限)。

顺便说一句,您可能想阅读“ chmod”联机帮助页(“ man 1 chmod”)。

希望这可以帮助 (?)...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

执行二进制文件时出现“无此文件或目录”错误

系统无法运行二进制文件-“无此文件或目录”

读取二进制文件时出现分段错误

在 runc 容器中执行二进制文件时出现分段错误

尽管具有“ rwx”特权和root用户,但执行二进制文件时权限被拒绝

尽管有“ rwx”特权,但在启动二进制文件时仍“拒绝权限”

执行.csh文件时出错:->无法执行二进制文件:EXEC格式错误

链接二进制文件以从其原始目录执行

尝试安装Eclipse时出现“ bash:./ eclipse:无法执行二进制文件”

bash错误:无法执行二进制文件

麻线显示“无此文件或目录”错误

读取二进制文件时出现问题

验证时出现Xcode错误-“您的二进制文件未针对iPhone 5优化”

在运行PyInstaller生成的二进制文件时出现模块导入错误

验证时出现Xcode错误-“您的二进制文件未针对iPhone 5优化”

追加和读取二进制文件时出现分段错误

启动npm时出现错误。找不到预构建的二进制文件

尝试在ELF二进制文件中执行注入的代码时收到分段错误

将二进制文件上传到github版本时保持可执行文件权限

当使用可执行二进制文件开发gem时,无法要求存在lib目录中的文件

ifstream二进制文件错误

AIX:无法执行二进制文件,0403-006执行许可被拒绝

以root身份运行的二进制文件对exec()的权限被拒绝

转换为二进制文件时出现Plink错误:.ped文件的第1行的令牌少于预期的数量

上载经过改造的文件时出现错误(无此文件或目录)

尝试包含头文件时,为什么会出现错误“无此文件或目录”?

网络中断发生时,位于已挂载的NFS目录上的二进制文件的执行是否会失败?

gcc编译的二进制文件给出“无法执行二进制文件”

除了将要执行的二进制文件之外,如何包含二进制文件?