PB5.44 - PB 5.51B1 - Compiled program flagged as Shared lib

Linux specific forum
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

PB5.44 - PB 5.51B1 - Compiled program flagged as Shared lib

Post by StarBootics »

Hello everyone,

Compiled program are flagged to be Shared libraries by the operating system.

https://www.dropbox.com/s/b5ocg471ydlb8 ... b.png?dl=0

They can be launch like a normal program via a *.desktop file. Unfortunately I don't create a *.desktop file for every program I create.

PB5.44 Beta 1 x64
Ubuntu Gnome 16.10 x64

Best regards
StarBootics
Last edited by StarBootics on Tue Dec 06, 2016 6:31 pm, edited 1 time in total.
The Stone Age did not end due to a shortage of stones !
User avatar
Keya
Addict
Addict
Posts: 1828
Joined: Thu Jun 04, 2015 7:10 am

Re: PB5.44 - Compiled program flagged as Shared lib

Post by Keya »

i havent had a chance to try 5.44 yet, but i wonder if it's just that flag in the ELF header then?
https://en.wikipedia.org/wiki/Executabl ... ble_Format
offset 0x10 (2 bytes) "e_type" 1=relocatable, 2=executable, 3=shared, 4=core

Code: Select all

Enumeration Elf_Type
  #ET_NONE
  #ET_REL
  #ET_EXEC
  #ET_DYN
  #ET_CORE
EndEnumeration

Procedure.s ELFType(sELFFile.s)
  Protected hFile, e_type.u, sType.s
  hFile = ReadFile(#PB_Any, sELFfile)
  If hFile
    FileSeek(hFile, $10)
    e_type = ReadWord(hFile)
    Select e_type
        Case #ET_REL:  sType = "Relocatable"
        Case #ET_EXEC: sType = "Executable"
        Case #ET_DYN:  sType = "Library"
        Case #ET_CORE: sType = "Core"
        Default: sType = "Other"
    EndSelect
    CloseFile(hFile)
    ProcedureReturn sType
  Else
    ProcedureReturn "Error"
  EndIf
EndProcedure

Debug ELFType("/tmp/myapp")
in which case it'd be easy enough to patch at least in the meantime!? :) ...

Code: Select all

Procedure.i SetELFType(sELFFile.s, e_type.u)
  Protected hFile, sType.s
  hFile = OpenFile(#PB_Any, sELFfile)
  If hFile
    FileSeek(hFile, $10)
    WriteWord(hFile, e_type)
    CloseFile(hFile)
    ProcedureReturn 1
  EndIf
EndProcedure

Debug ELFType("/tmp/myapp", #ET_EXEC) ;2
(and i take it you've already checked to ensure Compiler -> Compiler Options -> Executable Format to ensure that hasn't changed! sorry for silly Q but someone has to ask lol :))
DarkDragon
Addict
Addict
Posts: 2124
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: PB5.44 - Compiled program flagged as Shared lib

Post by DarkDragon »

[...] flagged to be Shared libraries by the operating system
What exactly do you mean? Is your file browser showing them as non-executables? Thats not the operating system then, but your file browser. Could it be that it is just not flagged as executable? I mean does chmod +x yourapp help?
bye,
Daniel
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

DarkDragon wrote:
[...] flagged to be Shared libraries by the operating system
What exactly do you mean? Is your file browser showing them as non-executables? Thats not the operating system then, but your file browser. Could it be that it is just not flagged as executable? I mean does chmod +x yourapp help?
What I mean : When you compile a program, it is considered as "application/x-sharedlib" and not as "application/x-executable". Did you take time to check the image I provide to show the problem ?

And this behavior appeared with the 5.44 version of the compiler. Program created with PB 5.50 on Ubuntu 16.04 are created as "application/x-executable".

Edit : By the way : chmod +x yourapp change absolutely nothing

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

Keya wrote:i havent had a chance to try 5.44 yet, but i wonder if it's just that flag in the ELF header then?
Sorry to be so late, and yes you hit the nail just right. When I run your code this is what I get in the debugger output :
Library
Unfortunately, patching the Executable make the patched program no longer launchable. There is something else somewhere to patch as well.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Fred
Administrator
Administrator
Posts: 14294
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.44 - Compiled program flagged as Shared lib

Post by Fred »

It's probably a detect error from your filemanager as PB executable are real executables.
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

Fred wrote:It's probably a detect error from your filemanager as PB executable are real executables.
Unfortunately, newly compiled program with PB 5.44 on Ubuntu Gnome 16.10 has Keya code's tell us, the eType Flag is equal to "Library" and not "Executable" and the program don't launch by double click on the filename in Nautilus. But programs created with PB V5.50 on Ubuntu Gnome 16.04 work as is on Ubuntu Gnome 16.10 and can be launched by a double click in Nautilus.

So why old program work as expected and new one don't that the question ?

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

Hello everyone,

Sorry for the long following code but I'm investigating ...

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Executable investigation
; File Name : Executable investigation.pb
; File version: 1.0.0
; Programming : Unknown - Experimental
; Programmed by : StarBootics
; Date : 26-11-2016
; Last Update : 28-11-2016
; PureBasic code : V5.44 Beta 2 LTS
; Platform : Ubuntu 16.10 (yakkety) x86-64
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule ELFHeader

  Declare ReadELFHeader(FileID.i)

  CompilerIf #PB_Compiler_Debugger
    Declare Debugging()
  CompilerEndIf

EndDeclareModule

Module ELFHeader

  Structure Instance

    Magic00.a
    Magic01.a
    Magic02.a
    Magic03.a
    Class.a
    Endian.a
    Version.a
    OSABI.a
    ABIVersion.a
    Padding.a[7]
    eType.u
    eMachine.u
    eVersion.l
    eEntry.i
    ePhOff.i
    eShOff.i
    eFlag.l
    eEhSize.u
    ePhEntSize.u
    ePhNum.u
    eShEntSize.u
    eShNum.u
    eShStrNdx.u

  EndStructure

  Global Instance.Instance

  Procedure ReadELFHeader(FileID.i)
    
    Instance\Magic00 = ReadAsciiCharacter(FileID)
    Instance\Magic01 = ReadAsciiCharacter(FileID)
    Instance\Magic02 = ReadAsciiCharacter(FileID)
    Instance\Magic03 = ReadAsciiCharacter(FileID)
    Instance\Class = ReadAsciiCharacter(FileID)
    Instance\Endian = ReadAsciiCharacter(FileID)
    Instance\Version = ReadAsciiCharacter(FileID)
    Instance\OSABI = ReadAsciiCharacter(FileID)
    Instance\ABIVersion = ReadAsciiCharacter(FileID)
    
    For PaddingID = 0 To 6
      Instance\Padding[PaddingID] = ReadAsciiCharacter(FileID)
    Next
    
    Instance\eType = ReadUnicodeCharacter(FileID)
    Instance\eMachine = ReadUnicodeCharacter(FileID)
    Instance\eVersion = ReadLong(FileID)
    Instance\eEntry = ReadInteger(FileID)
    Instance\ePhOff = ReadInteger(FileID)
    Instance\eShOff = ReadInteger(FileID)
    Instance\eFlag = ReadLong(FileID)
    Instance\eEhSize = ReadUnicodeCharacter(FileID)
    Instance\ePhEntSize = ReadUnicodeCharacter(FileID)
    Instance\ePhNum = ReadUnicodeCharacter(FileID)
    Instance\eShEntSize = ReadUnicodeCharacter(FileID)
    Instance\eShNum = ReadUnicodeCharacter(FileID)
    Instance\eShStrNdx = ReadUnicodeCharacter(FileID)
    
  EndProcedure

  CompilerIf #PB_Compiler_Debugger

    Procedure Debugging()
    
      Debug "Magic Number : " + Hex(Instance\Magic00) + " " + Chr(Instance\Magic01) + Chr(Instance\Magic02) + Chr(Instance\Magic03)
      
      Select Instance\Class
          
        Case 1
          Debug "Class : 32-bit format"
          
        Case 2
          Debug "Class : 64-bit format"
          
      EndSelect
      
          
      Select Instance\Endian
          
        Case 1
          Debug "Endian : Little"
          
        Case 2
          Debug "Endian : Big"
          
      EndSelect
                
      Debug "Version : " + Str(Instance\Version)
     
      Select Instance\OSABI
          
        Case $00
          Debug "OSABI : System V"
          
        Case $01 	
          Debug "OSABI : HP-UX"
          
        Case $02 
          Debug "OSABI : NetBSD"
          
        Case $03 
          Debug "OSABI : Linux"
          
        Case $06 	
          Debug "OSABI : Solaris"
          
        Case $07 	
          Debug "OSABI : AIX"
          
        Case $08 	
          Debug "OSABI : IRIX"
          
        Case $09 	
          Debug "OSABI : FreeBSD"
          
        Case $0C 	
          Debug "OSABI : OpenBSD"
          
        Case $0D 	
          Debug "OSABI : OpenVMS"
          
        Case $0E 	
          Debug "OSABI : NonStop Kernel"
          
        Case $0F 	
          Debug "OSABI : AROS"
          
        Case $10 	
          Debug "OSABI : Fenix OS"
          
        Case $11 	
          Debug "OSABI : CloudABI"
        
        Case $53 	
          Debug "OSABI : Sortix"
          
      EndSelect 

      Debug "ABIVersion : " + Str(Instance\ABIVersion)
    
;       For PaddingID = 0 To 6
;         Debug Instance\Padding[PaddingID]
;       Next
    
      Select Instance\eType
          
        Case 1    
          Debug "Type : relocatable"
          
        Case 2
          Debug "Type : executable"
          
        Case 3
          Debug "Type : Library"
          
        Case 4
          Debug "Type : Core"
          
      EndSelect 
      
      
      
      Select Instance\eMachine
          
        Case $00 	
          Debug "Machine : No specific instruction set"
          
        Case $02 	
          Debug "Machine : SPARC"
          
        Case $03 	
          Debug "Machine : x86"
          
        Case $08 	
          Debug "Machine : MIPS"
          
        Case $14 	
          Debug "Machine : PowerPC"
          
        Case $28 	
          Debug "Machine : ARM"
          
        Case $2A 	
          Debug "Machine : SuperH"
          
        Case $32 	
          Debug "Machine : IA-64"
          
        Case $3E 	
          Debug "Machine : x86-64"
          
        Case $B7 	
          Debug "Machine : AArch64"
          
          
      EndSelect
      
      
          
      Debug "eVersion : " + Str(Instance\eVersion)
      Debug "eEntry : " + Str(Instance\eEntry)
      Debug "ePhOff : " + Str(Instance\ePhOff)
      Debug "eShOff : " + Str(Instance\eShOff)
      Debug "eFlag : " + Str(Instance\eFlag)
      Debug "eEhSize : " + Str(Instance\eEhSize)
      Debug "ePhEntSize : " + Str(Instance\ePhEntSize)
      Debug "ePhNum : " + Str(Instance\ePhNum)
      Debug "eShEntSize : " + Str(Instance\eShEntSize)
      Debug "eShNum : " + Str(Instance\eShNum)
      Debug "eShStrNdx : " + Str(Instance\eShStrNdx)
    
    EndProcedure

  CompilerEndIf

EndModule

DeclareModule ProgramHeader

  Declare ReadProgramHeader(FileID.i)

  CompilerIf #PB_Compiler_Debugger
    Declare Debugging()
  CompilerEndIf

EndDeclareModule

Module ProgramHeader

  Structure Instance

    Type.l
    Offset.l
    VAddr.l
    PAddr.l
    FileSize.l
    MemSize.l
    Flags.l
    Align.l

  EndStructure

  Global Instance.Instance

  Procedure ReadProgramHeader(FileID.i)
    
    Instance\Type = ReadLong(FileID)
    Instance\Offset = ReadLong(FileID)
    Instance\VAddr = ReadLong(FileID)
    Instance\PAddr = ReadLong(FileID)
    Instance\FileSize = ReadLong(FileID)
    Instance\MemSize = ReadLong(FileID)
    Instance\Flags = ReadLong(FileID)
    Instance\Align = ReadLong(FileID)
    
  EndProcedure

  CompilerIf #PB_Compiler_Debugger

    Procedure Debugging()
    
      Select Instance\Type
        Case $00000000 	
          Debug "Type : PT_NULL"
        Case $00000001 	
          Debug "Type : PT_LOAD"
        Case $00000002 	
          Debug "Type : PT_DYNAMIC"
        Case $00000003 	
          Debug "Type : PT_INTERP"
        Case $00000004 	
          Debug "Type : PT_NOTE"
        Case $00000005 	
          Debug "Type : PT_SHLIB"
        Case $00000006 	
          Debug "Type : PT_PHDR"
          
        Case $60000000 	
          Debug "Type : PT_LOOS"
        Case $6FFFFFFF 	
          Debug "Type : PT_HIOS"
        Case $70000000 	
          Debug "Type : PT_LOPROC"
        Case $7FFFFFFF 	
          Debug "Type : PT_HIPROC"
          
      EndSelect
      
          
      Debug "Offset : " + Str(Instance\Offset)
      Debug "VAddr : " + Str(Instance\VAddr)
      Debug "PAddr : " + Str(Instance\PAddr)
      Debug "FileSize : " + Str(Instance\FileSize)
      Debug "MemSize : " + Str(Instance\MemSize)
      Debug "Flags : " + Str(Instance\Flags)
      Debug "Align : " + Str(Instance\Align)
    
    EndProcedure

  CompilerEndIf

EndModule

ExeFileName.s = OpenFileRequester("Select Exe to analyze", GetHomeDirectory(), "", 1)

If ExeFileName <> ""
  
  FileHandle = ReadFile(#PB_Any, ExeFileName)
  
  If FileHandle
    ELFHeader::ReadELFHeader(FileHandle)
    ProgramHeader::ReadProgramHeader(FileHandle)
    CloseFile(FileHandle)
    ELFHeader::Debugging()
    Debug ""
    ProgramHeader::Debugging()
  EndIf
 
EndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
When I run the code above on an executable created with PB 5.50 x64 on Ubuntu Gnome 16.04 this what I got :
Magic Number : 7F ELF
Class : 64-bit format
Endian : Little
Version : 1
OSABI : System V
ABIVersion : 0
Type : executable
Machine : x86-64
eVersion : 1
eEntry : 4211216
ePhOff : 64
eShOff : 137248
eFlag : 0
eEhSize : 64
ePhEntSize : 56
ePhNum : 9
eShEntSize : 64
eShNum : 28
eShStrNdx : 27

Type : PT_PHDR
Offset : 5
VAddr : 64
PAddr : 0
FileSize : 4194368
MemSize : 0
Flags : 4194368
Align : 0
And the same program compiled with PB 5.44 x64 on Ubuntu Gnome 16.10
Magic Number : 7F ELF
Class : 64-bit format
Endian : Little
Version : 1
OSABI : System V
ABIVersion : 0
Type : Library
Machine : x86-64
eVersion : 1
eEntry : 20480
ePhOff : 64
eShOff : 214608
eFlag : 0
eEhSize : 64
ePhEntSize : 56
ePhNum : 9
eShEntSize : 64
eShNum : 29
eShStrNdx : 28

Type : PT_PHDR
Offset : 5
VAddr : 64
PAddr : 0
FileSize : 64
MemSize : 0
Flags : 64
Align : 0
So we have differences in both ELFHeader and ProgramHeader. But as far I can tell the ProgramHeader are for 32 bit program so I'm not 100% sure about that.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Fred
Administrator
Administrator
Posts: 14294
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.44 - Compiled program flagged as Shared lib

Post by Fred »

Could you give it a try to 5.43 to see if it's a regression ?
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

Hello Fred,

With PB 5.42 and 5.43 I get a linker error : https://www.dropbox.com/s/56ogd435czs1t ... r.png?dl=0

Sorry to not help more than that. But apparently something change between Ubuntu 16.04 and 16.10 that screwed up PureBasic Big Time !

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - Compiled program flagged as Shared lib

Post by StarBootics »

Hello,

Not much new to say beside the problem is also present with PB 5.51 Beta 1.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
arma
User
User
Posts: 51
Joined: Sun Jul 24, 2016 11:54 pm

Re: PB5.44 - PB 5.51B1 - Compiled program flagged as Shared

Post by arma »

I have the same problem!
I was thinking, that was not a problem at first because of beta! I was thinking it will change after finish beta versions!
But nothing changed!
PureBasic v5.44 doesnt produce real executable on Ubuntu 16.10!
I am sure now this is a problem...
Fred
Administrator
Administrator
Posts: 14294
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.44 - PB 5.51B1 - Compiled program flagged as Shared

Post by Fred »

After some investigation, this is a bug in Ubuntu 16.10

https://ubuntuforums.org/showthread.php?t=2341593

I tested myself with this small C program:

Code: Select all

#include <stdio.h>

int main()
{
  printf("Hello\n");
  return 0;
}
compiled as

Code: Select all

gcc prog.c -o a.out
result of 'file'

Code: Select all

$ file a.out 
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=675e42f7d8e14cd7192dbbf04cf452a7410f1696, not stripped


result of file for the purebasic exe compiled in Ubuntu 14.10 with the same PB compiler

Code: Select all

$ file Desktop/purebasic/compilers/purebasic 
Desktop/purebasic/compilers/purebasic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=318cc52976319169b18da985abb3555c22d9b7c1, stripped
So there is a regression in Ubuntu and we need to wait for a patch
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 703
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB5.44 - PB 5.51B1 - Compiled program flagged as Shared

Post by StarBootics »

Thanks for the info.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
arma
User
User
Posts: 51
Joined: Sun Jul 24, 2016 11:54 pm

Re: PB5.44 - PB 5.51B1 - Compiled program flagged as Shared

Post by arma »

Any solution?
Or just wait for Ubuntu update?
Post Reply