[SOLVED] no information about required shared lib

Programming, for all ages and all languages.
Post Reply
User avatar
CorruptedByCPU
Member
Member
Posts: 78
Joined: Tue Feb 11, 2014 4:59 pm

[SOLVED] no information about required shared lib

Post by CorruptedByCPU »

Hey! Referring to previous post viewtopic.php?f=13&t=56576.

My "main" program has no information about what library is required to run properly.

There is no dynamic section in this file.

So, I'm a little stuck for implementing Dynamic Linking.

Code: Select all

  ~/test  readelf -a main                                                                                                                                                                                                         ✔ 
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:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4976 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         5
  Size of section headers:           64 (bytes)
  Number of section headers:         14
  Section header string table index: 13

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  00001000
       000000000000000a  0000000000000000  AX       0     0     16
  [ 2] .plt              PROGBITS         0000000000000010  00001010
       0000000000000020  0000000000000010  AX       0     0     16
  [ 3] .dynsym           DYNSYM           0000000000001030  00001030
       0000000000000030  0000000000000018   A       4     1     8
  [ 4] .dynstr           STRTAB           0000000000001060  00001060
       000000000000001d  0000000000000000   A       0     0     1
  [ 5] .hash             HASH             0000000000001080  00001080
       0000000000000014  0000000000000004   A       3     0     8
  [ 6] .gnu.hash         GNU_HASH         0000000000001098  00001098
       000000000000001c  0000000000000000   A       3     0     8
  [ 7] .rela.dyn         RELA             00000000000010b8  000010b8
       0000000000000018  0000000000000018   A       3     0     8
  [ 8] .dynamic          DYNAMIC          00000000000020d0  000010d0
       0000000000000120  0000000000000010  WA       4     0     8
  [ 9] .got.plt          PROGBITS         00000000000021f0  000011f0
       0000000000000020  0000000000000008  WA       0     0     8
  [10] .comment          PROGBITS         0000000000000000  00001210
       0000000000000015  0000000000000001  MS       0     0     1
  [11] .symtab           SYMTAB           0000000000000000  00001228
       00000000000000a8  0000000000000018          12     5     8
  [12] .strtab           STRTAB           0000000000000000  000012d0
       000000000000003e  0000000000000000           0     0     1
  [13] .shstrtab         STRTAB           0000000000000000  0000130e
       0000000000000060  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  NULL           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000         0x8
  LOAD           0x0000000000001000 0x0000000000000000 0x0000000000000000
                 0x0000000000000030 0x0000000000000030  R E    0x1000
  LOAD           0x0000000000001030 0x0000000000001030 0x0000000000001030
                 0x00000000000000a0 0x00000000000000a0  R      0x1000
  LOAD           0x00000000000010d0 0x00000000000020d0 0x00000000000020d0
                 0x0000000000000140 0x0000000000000140  RW     0x1000
  LOAD           0x0000000000001030 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x1000

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .text .plt 
   02     .dynsym .dynstr .hash .gnu.hash .rela.dyn 
   03     .dynamic .got.plt 
   04     

There is no dynamic section in this file.

Relocation section '.rela.dyn' at offset 0x10b8 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000002208  000100000007 R_X86_64_JUMP_SLO 0000000000000000 font_char_length + 0
No processor specific unwind information to decode

Symbol table '.dynsym' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND font_char_length

Symbol table '.symtab' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS main.c
     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
     3: 00000000000020d0     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
     4: 00000000000021f0     0 OBJECT  LOCAL  DEFAULT    9 _GLOBAL_OFFSET_TABLE_
     5: 0000000000000000    10 FUNC    GLOBAL DEFAULT    1 entry
     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND font_char_length

No version information found in this file.
Last edited by CorruptedByCPU on Wed Nov 16, 2022 1:56 pm, edited 1 time in total.
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: no information about required shared lib

Post by iansjack »

In your LD flags you specified --no-dynamic-linker.
User avatar
CorruptedByCPU
Member
Member
Posts: 78
Joined: Tue Feb 11, 2014 4:59 pm

Re: no information about required shared lib

Post by CorruptedByCPU »

iansjack wrote:In your LD flags you specified --no-dynamic-linker.
Without it is the same problem :)
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: no information about required shared lib

Post by iansjack »

You also use the “static” option.
User avatar
CorruptedByCPU
Member
Member
Posts: 78
Joined: Tue Feb 11, 2014 4:59 pm

Re: no information about required shared lib

Post by CorruptedByCPU »

iansjack wrote:You also use the “static” option.
Did You even check that? :) Without this option, result will be the same.

Code: Select all

~/test $ cat make.sh                                                                                 0|1 ✘ 
CFLAGS="-Ofast -march=x86-64 -nostdlib -m64"
LDFLAGS="-nostdlib"

clang -c -fpic font.c ${CFLAGS}
clang -shared -o libfont.so font.o ${CFLAGS}

clang -c main.c -o main.o ${CFLAGS}
ld -L. main.o -o main -lfont -T linker.software ${LDFLAGS}

Code: Select all

~/test $ readelf -a main | grep libfont.so
~/test $ 
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: no information about required shared lib

Post by iansjack »

It’s not my job to check anything. I’ve got better uses for my time than debugging other people’s code. But I’m happy to point out obvious errors.

At least you have now detailed the actual commands you are using.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: no information about required shared lib

Post by Octocontrabass »

akasei wrote:

Code: Select all

-T linker.software
Perhaps there's something wrong with your linker script.
User avatar
CorruptedByCPU
Member
Member
Posts: 78
Joined: Tue Feb 11, 2014 4:59 pm

Re: no information about required shared lib

Post by CorruptedByCPU »

Octocontrabass wrote:
akasei wrote:

Code: Select all

-T linker.software
Perhaps there's something wrong with your linker script.
My bad, I didn't include that file.

Code: Select all

OUTPUT_FORMAT( elf64-x86-64 )
OUTPUT_ARCH( i386:x86-64 )

ENTRY( entry )

PHDRS
{
	null   PT_NULL FLAGS(0) ;                   /* Null segment */
	text   PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
	rodata PT_LOAD FLAGS((1 << 2)) ;            /* Read only */
	data   PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
	bss    PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
}

SECTIONS
{
    . = 0x0000000000000000;

    .text : {
        *(.text .text.*)
    } :text

    . += CONSTANT(MAXPAGESIZE);

    .rodata : {
        *(.rodata .rodata.*)
    } :rodata

    . += CONSTANT(MAXPAGESIZE);

    .data : {
        *(.data .data.*)
    } :data

    .bss : {
        *(COMMON)
        *(.bss .bss.*)
    } :bss
}
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: no information about required shared lib

Post by Octocontrabass »

akasei wrote:There is no dynamic section in this file.
There is no PT_DYNAMIC section in your PHDRS.
User avatar
CorruptedByCPU
Member
Member
Posts: 78
Joined: Tue Feb 11, 2014 4:59 pm

Re: no information about required shared lib

Post by CorruptedByCPU »

Octocontrabass wrote:
akasei wrote:There is no dynamic section in this file.
There is no PT_DYNAMIC section in your PHDRS.
Oh my. I didn't know about this entry :( Thank You.

Code: Select all

Dynamic section at offset 0x1150 contains 13 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libfont.so]
 0x0000000000000004 (HASH)               0x10c0
 0x000000006ffffef5 (GNU_HASH)           0x10d8
 0x0000000000000005 (STRTAB)             0x10a0
 0x0000000000000006 (SYMTAB)             0x1070
 0x000000000000000a (STRSZ)              29 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x2270
 0x0000000000000002 (PLTRELSZ)           24 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x1138
 0x0000000000000000 (NULL)               0x0
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
Post Reply