Skip to content

Instantly share code, notes, and snippets.

@fzakaria
Created March 7, 2022 17:09
Show Gist options
  • Save fzakaria/de117012d31c7145ff6fa2e81b1fcbe5 to your computer and use it in GitHub Desktop.
Save fzakaria/de117012d31c7145ff6fa2e81b1fcbe5 to your computer and use it in GitHub Desktop.
Largest RPATH in /nix/store/*/bin
#!/usr/bin/env ruby
require 'find'
require 'elftools'
STORE = "/nix/store/*/bin/*"
puts "Searching /nix/store for rpath entries."
seen = 0
current = ""
enum = Dir.glob(STORE).lazy.map do | path|
seen += 1
current = path
next ["", "", 0] unless File.file? path
# some .debug files have a crazy amount of dynamic tags
next ["", "", 0] if path.end_with? ".debug"
begin
file = ELFTools::ELFFile.new(File.open(path))
sections = file.sections_by_type(:dynamic)
next ["", "", 0] if sections.nil? || sections.count.zero?
section = sections.map do |section|
rpath = section.tag_by_type(ELFTools::Constants::DT_RUNPATH).value.split(':')
[path, rpath, rpath.count]
end.max do |a, b|
a[2] <=> b[2]
end
next section
rescue => e
# do nothing
# puts e
next ["", "", 0]
end
end
Thread.new do
while true do
puts "Seen: #{seen} Current: #{current}"
sleep 30
end
end
max = enum.max do |a, b|
a[2] <=> b[2]
end
puts max
@fzakaria
Copy link
Author

fzakaria commented Mar 7, 2022

You'll need to do gem install --user elftools or the equivalent.
I need to make this a real package and Nix package it.... I know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment