바이너리를 실행할 때 "해당 파일이나 디렉터리가 없습니다" 오류가 발생하고 권한 거부도 표시됩니다.

바이너리를 실행할 때 "해당 파일이나 디렉터리가 없습니다" 오류가 발생하고 권한 거부도 표시됩니다.
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.

$ 파일 datasize.o

datasize.o: ELF 64비트 LSB 재배치 가능, x86-64, 버전 1(SYSV), 제거되지 않음

실행할 수 없습니다:-

./datasize.o

bash: ./datasize.o: 권한이 거부되었습니다.

ldd를 사용해도

ldd 데이터 크기.o

ldd: 경고: 동적 실행 파일이 아닌 `./datasize.o'에 대한 실행 권한이 없습니다.

추적의 출력

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.

답변1

실제로 ".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")를 읽어보는 것이 좋습니다.

도움이 되었기를 바랍니다 (?)...

답변2

.o 파일을 실행할 수 없습니다. 링크가 필요하고 최종 실행 파일이 생성되어야 합니다. 일반적으로 수행되는 방식은 "gcc -o file.c"이거나 컴파일 및 링크가 별도의 단계로 수행됩니다.

관련 정보