Module: ELFShim Private

Defined in:
Library/Homebrew/os/linux/elf.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Pathname extension for dealing with ELF files.

Instance Method Summary collapse

Instance Method Details

#archObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


58
59
60
61
62
63
64
65
66
67
68
69
# File 'Library/Homebrew/os/linux/elf.rb', line 58

def arch
  return :dunno unless elf?

  @arch ||= case read_uint16(ARCHITECTURE_OFFSET)
  when ARCHITECTURE_I386 then :i386
  when ARCHITECTURE_X86_64 then :x86_64
  when ARCHITECTURE_POWERPC then :powerpc
  when ARCHITECTURE_ARM then :arm
  when ARCHITECTURE_AARCH64 then :arm64
  else :dunno
  end
end

#binary_executable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

85
86
87
# File 'Library/Homebrew/os/linux/elf.rb', line 85

def binary_executable?
  elf_type == :executable
end

#dylib?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

81
82
83
# File 'Library/Homebrew/os/linux/elf.rb', line 81

def dylib?
  elf_type == :dylib
end

#dylib_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


165
166
167
# File 'Library/Homebrew/os/linux/elf.rb', line 165

def dylib_id
  .dylib_id
end

#dynamic_elf?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

101
102
103
104
105
# File 'Library/Homebrew/os/linux/elf.rb', line 101

def dynamic_elf?
  return @dynamic_elf if defined? @dynamic_elf

  @dynamic_elf = patchelf_patcher.elf.segment_by_type(:DYNAMIC).present?
end

#dynamically_linked_librariesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


169
170
171
# File 'Library/Homebrew/os/linux/elf.rb', line 169

def dynamically_linked_libraries(*)
  .dylibs
end

#elf?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

49
50
51
52
53
54
55
56
# File 'Library/Homebrew/os/linux/elf.rb', line 49

def elf?
  return @elf if defined? @elf
  return @elf = false unless read(MAGIC_NUMBER_ASCII.size, MAGIC_NUMBER_OFFSET) == MAGIC_NUMBER_ASCII

  # Check that this ELF file is for Linux or System V.
  # OS_ABI is often set to 0 (System V), regardless of the target platform.
  @elf = [OS_ABI_LINUX, OS_ABI_SYSTEM_V].include? read_uint8(OS_ABI_OFFSET)
end

#elf_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


71
72
73
74
75
76
77
78
79
# File 'Library/Homebrew/os/linux/elf.rb', line 71

def elf_type
  return :dunno unless elf?

  @elf_type ||= case read_uint16(TYPE_OFFSET)
  when TYPE_EXECUTABLE then :executable
  when TYPE_SHARED then :dylib
  else :dunno
  end
end

#interpreterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


95
96
97
98
99
# File 'Library/Homebrew/os/linux/elf.rb', line 95

def interpreter
  return @interpreter if defined? @interpreter

  @interpreter = patchelf_patcher.interpreter
end

#patchelf_patcherObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


155
156
157
158
# File 'Library/Homebrew/os/linux/elf.rb', line 155

def patchelf_patcher
  require "patchelf"
  @patchelf_patcher ||= PatchELF::Patcher.new to_s, on_error: :silent
end

#read_uint16(offset) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
# File 'Library/Homebrew/os/linux/elf.rb', line 45

def read_uint16(offset)
  read(2, offset).unpack1("v")
end

#read_uint8(offset) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


41
42
43
# File 'Library/Homebrew/os/linux/elf.rb', line 41

def read_uint8(offset)
  read(1, offset).unpack1("C")
end

#rpathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


89
90
91
92
93
# File 'Library/Homebrew/os/linux/elf.rb', line 89

def rpath
  return @rpath if defined? @rpath

  @rpath = rpath_using_patchelf_rb
end

#rpath_using_patchelf_rbObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


151
152
153
# File 'Library/Homebrew/os/linux/elf.rb', line 151

def rpath_using_patchelf_rb
  patchelf_patcher.runpath || patchelf_patcher.rpath
end