Module: ELFShim Private

Included in:
Pathname
Defined in:
os/linux/elf.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Pathname extension for dealing with ELF files.

Instance Method Summary collapse

Instance Method Details

#archObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



58
59
60
61
62
63
64
65
66
67
68
69
# File '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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


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

def binary_executable?
  elf_type == :executable
end

#dylib?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


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

def dylib?
  elf_type == :dylib
end

#dylib_idObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



184
185
186
# File 'os/linux/elf.rb', line 184

def dylib_id
  .dylib_id
end

#dynamic_elf?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


115
116
117
118
119
# File 'os/linux/elf.rb', line 115

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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



188
189
190
# File 'os/linux/elf.rb', line 188

def dynamically_linked_libraries(*)
  .dylibs
end

#elf?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


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

def elf?
  return @elf if defined? @elf
  return @elf = false if 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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



71
72
73
74
75
76
77
78
79
# File '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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



103
104
105
106
107
# File 'os/linux/elf.rb', line 103

def interpreter
  return @interpreter if defined? @interpreter

  @interpreter = patchelf_patcher.interpreter
end

#patch!(interpreter: nil, rpath: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



109
110
111
112
113
# File 'os/linux/elf.rb', line 109

def patch!(interpreter: nil, rpath: nil)
  return if interpreter.blank? && rpath.blank?

  save_using_patchelf_rb interpreter, rpath
end

#patchelf_patcherObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



174
175
176
177
# File 'os/linux/elf.rb', line 174

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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



45
46
47
# File '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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



41
42
43
# File '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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

The runtime search path, such as: “/lib:/usr/lib:/usr/local/lib”



91
92
93
94
95
# File 'os/linux/elf.rb', line 91

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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



170
171
172
# File 'os/linux/elf.rb', line 170

def rpath_using_patchelf_rb
  patchelf_patcher.runpath || patchelf_patcher.rpath
end

#rpathsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

An array of runtime search path entries, such as: [“/lib”, “/usr/lib”, “/usr/local/lib”]



99
100
101
# File 'os/linux/elf.rb', line 99

def rpaths
  Array(rpath&.split(":"))
end

#save_using_patchelf_rb(new_interpreter, new_rpath) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



163
164
165
166
167
168
# File 'os/linux/elf.rb', line 163

def save_using_patchelf_rb(new_interpreter, new_rpath)
  patcher = patchelf_patcher
  patcher.interpreter = new_interpreter if new_interpreter.present?
  patcher.rpath = new_rpath if new_rpath.present?
  patcher.save(patchelf_compatible: true)
end