Module: ELFShim Private

Extended by:
T::Helpers
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.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'os/linux/elf.rb', line 64

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 :ppc32
  when ARCHITECTURE_POWERPC64 then :ppc64
  when ARCHITECTURE_ARM then :arm
  when ARCHITECTURE_AARCH64 then :arm64
  else :dunno
  end
end

#arch_compatible?(wanted_arch) ⇒ 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)


78
79
80
81
82
83
84
85
# File 'os/linux/elf.rb', line 78

def arch_compatible?(wanted_arch)
  return true unless elf?

  # Treat ppc64le and ppc64 the same
  wanted_arch = :ppc64 if wanted_arch == :ppc64le

  wanted_arch == arch
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)


101
102
103
# File 'os/linux/elf.rb', line 101

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)


97
98
99
# File 'os/linux/elf.rb', line 97

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.



233
234
235
# File 'os/linux/elf.rb', line 233

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)


131
132
133
134
135
# File 'os/linux/elf.rb', line 131

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.



237
238
239
# File 'os/linux/elf.rb', line 237

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)


55
56
57
58
59
60
61
62
# File 'os/linux/elf.rb', line 55

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.



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

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.



119
120
121
122
123
# File 'os/linux/elf.rb', line 119

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.



125
126
127
128
129
# File 'os/linux/elf.rb', line 125

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.



223
224
225
226
# File 'os/linux/elf.rb', line 223

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.



51
52
53
# File 'os/linux/elf.rb', line 51

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.



47
48
49
# File 'os/linux/elf.rb', line 47

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"



107
108
109
110
111
# File 'os/linux/elf.rb', line 107

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.



219
220
221
# File 'os/linux/elf.rb', line 219

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"]



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

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.



212
213
214
215
216
217
# File 'os/linux/elf.rb', line 212

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