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
- #arch ⇒ Object private
- #binary_executable? ⇒ Boolean private
- #dylib? ⇒ Boolean private
- #dylib_id ⇒ Object private
- #dynamic_elf? ⇒ Boolean private
- #dynamically_linked_libraries ⇒ Object private
- #elf? ⇒ Boolean private
- #elf_type ⇒ Object private
- #interpreter ⇒ Object private
- #patch!(interpreter: nil, rpath: nil) ⇒ Object private
- #patchelf_patcher ⇒ Object private
- #read_uint16(offset) ⇒ Object private
- #read_uint8(offset) ⇒ Object private
- #rpath ⇒ Object private
- #rpath_using_patchelf_rb ⇒ Object private
- #save_using_patchelf(new_interpreter, new_rpath) ⇒ Object private
- #save_using_patchelf_rb(new_interpreter, new_rpath) ⇒ Object private
Instance Method Details
#arch ⇒ 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.
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.
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.
81 82 83 |
# File 'Library/Homebrew/os/linux/elf.rb', line 81 def dylib? elf_type == :dylib end |
#dylib_id ⇒ 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.
192 193 194 |
# File 'Library/Homebrew/os/linux/elf.rb', line 192 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.
111 112 113 114 115 |
# File 'Library/Homebrew/os/linux/elf.rb', line 111 def dynamic_elf? return @dynamic_elf if defined? @dynamic_elf @dynamic_elf = patchelf_patcher.elf.segment_by_type(:DYNAMIC).present? end |
#dynamically_linked_libraries ⇒ 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.
196 197 198 |
# File 'Library/Homebrew/os/linux/elf.rb', line 196 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.
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_type ⇒ 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.
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 |
#interpreter ⇒ 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.
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 |
#patch!(interpreter: nil, rpath: nil) ⇒ 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.
101 102 103 104 105 106 107 108 109 |
# File 'Library/Homebrew/os/linux/elf.rb', line 101 def patch!(interpreter: nil, rpath: nil) return if interpreter.blank? && rpath.blank? if HOMEBREW_PATCHELF_RB_WRITE save_using_patchelf_rb interpreter, rpath else save_using_patchelf interpreter, rpath end end |
#patchelf_patcher ⇒ 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.
182 183 184 185 |
# File 'Library/Homebrew/os/linux/elf.rb', line 182 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 |
#rpath ⇒ 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.
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_rb ⇒ 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.
178 179 180 |
# File 'Library/Homebrew/os/linux/elf.rb', line 178 def rpath_using_patchelf_rb patchelf_patcher.runpath || patchelf_patcher.rpath end |
#save_using_patchelf(new_interpreter, new_rpath) ⇒ 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.
161 162 163 164 165 166 167 168 169 |
# File 'Library/Homebrew/os/linux/elf.rb', line 161 def save_using_patchelf(new_interpreter, new_rpath) patchelf = DevelopmentTools.locate "patchelf" odie "Could not locate patchelf, please: brew install patchelf." if patchelf.blank? args = [] args << "--set-interpreter" << new_interpreter if new_interpreter.present? args << "--force-rpath" << "--set-rpath" << new_rpath if new_rpath.present? Homebrew.safe_system(patchelf, *args, to_s) end |
#save_using_patchelf_rb(new_interpreter, new_rpath) ⇒ 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.
171 172 173 174 175 176 |
# File 'Library/Homebrew/os/linux/elf.rb', line 171 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 |