46 Commits

Author SHA1 Message Date
Mike McQuaid
d57efd9ea2
Improve some Pathname instance variable handling
Will fix or at least partly address:
```
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/os/linux/elf.rb:225: warning: The class Pathname reached 8 shape variations, instance variables accesses will be slower and memory usage increased.
35
It is recommended to define instance variables in a consistent order, for instance by eagerly defining them all in the #initialize method.
```
2025-07-11 08:02:27 +00:00
Douglas Eichelberger
d3d25beb35 Use requires_ancestor consistently 2024-10-06 09:25:57 -07:00
Bo Anderson
c76c902dbc
os/linux/elf: fix arch compat check on ppc 2024-10-01 05:32:58 +01:00
Carlo Cabrera
861d7b9087
linkage_checker: skip files with incompatible architectures
Some formulae include these files, and they can't always be removed.
However, they can cause spurious linkage failures, so let's skip them
when checking for linkage. See, for example, faust at
Homebrew/homebrew-core#191308.
2024-09-29 05:15:36 +08:00
Issy Long
45978435e7
rubocop: Use Sorbet/StrictSigil as it's better than comments
- Previously I thought that comments were fine to discourage people from
  wasting their time trying to bump things that used `undef` that Sorbet
  didn't support. But RuboCop is better at this since it'll complain if
  the comments are unnecessary.

- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.

- I've gone for a mixture of `rubocop:disable` for the files that can't
  be `typed: strict` (use of undef, required before everything else, etc)
  and `rubocop:todo` for everything else that should be tried to make
  strictly typed. There's no functional difference between the two as
  `rubocop:todo` is `rubocop:disable` with a different name.

- And I entirely disabled the cop for the docs/ directory since
  `typed: strict` isn't going to gain us anything for some Markdown
  linting config files.

- This means that now it's easier to track what needs to be done rather
  than relying on checklists of files in our big Sorbet issue:

```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
    268
```

- And this is confirmed working for new files:

```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        Library/Homebrew/bad.rb
        Library/Homebrew/good.rb

nothing added to commit but untracked files present (use "git add" to track)

$ brew style
Offenses:

bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^

1340 files inspected, 1 offense detected
```
2024-08-12 15:24:27 +01:00
Carlo Cabrera
5e027bffd6
Merge pull request #17149 from alebcay/elf-expand-origin
elf: expand $ORIGIN in RUNPATH/RPATH entries
2024-04-28 01:14:54 +08:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Caleb Xu
6ee34832d1
elf: expand $ORIGIN in RUNPATH/RPATH entries 2024-04-25 22:52:25 -04:00
Ruoyu Zhong
916b37388d
Revert "Revert "os/linux/elf: avoid using ldd for listing dynamic dependencies"" 2024-04-24 02:23:13 +08:00
Ruoyu Zhong
852c5acb65
Revert "os/linux/elf: avoid using ldd for listing dynamic dependencies" 2024-04-16 02:50:12 +08:00
Caleb Xu
a4e0ccc1f6
os/linux/elf: avoid using ldd for listing dynamic dependencies 2024-04-13 19:35:30 -04:00
Issy Long
f4218a6316
Fix RuboCop Performance/MapCompact offenses
- Rename an iterator variable since it would make the line too long.
2024-02-25 22:59:59 +00:00
Douglas Eichelberger
08af78a2a5 brew style --fix 2023-04-25 09:26:24 -07:00
Douglas Eichelberger
adfd12cfd0 Enable more typing 2023-03-21 21:42:51 -07:00
Carlo Cabrera
25910b9c68
Use Array.
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2022-08-26 22:29:55 +08:00
Carlo Cabrera
ab696cbbb7
linux/diagnostic: fix rpath returning nil.
Fixes #13762.

There's still a bug in the GCC linkage check, but I'll need a bit more
time to work on a fix. This at least makes sure `brew doctor` will not
return the error in the issue linked above.
2022-08-26 22:23:02 +08:00
Chris Araman
caf310038f
linkage: display executables with missing rpath
An executable that links against @rpath-prefixed dylibs must include at least
one runtime path. This will prevent issues like the one resolved in #91485.

Caveats:
1. This won't find executables that have only recursive dylib dependencies with
   @rpath prefixes.
2. This makes no attempt to resolve @rpath, @executable_path or @loader_path
   dylibs, or to verify the correctness of any LC_RPATH entries, or to
   otherwise simulate dlopen logic.
3. Weakly-linked dylibs are still excluded from the search for broken linkage.

The scope is narrow in order to focus on this particular problem. It is meant
only as a sanity check.
2021-12-20 13:44:35 -08:00
Bo Anderson
9493cbb80a
os/linux/elf: don't report missing libraries to dependents 2021-10-31 17:03:29 +00:00
Mike McQuaid
0cda6a0657
Only use patchelf.rb
Remove support for using the `patchelf` formula for writing as it's been
off by default for a long time now.
2021-10-19 15:15:56 +01:00
Carlo Cabrera
d696250ddb
Fix ELF architecture offset for x86_64
The current offset results in ELF binaries returning an `#arch` of
`:dunno`.

Also, skip the `check_binary_arches` audit on the generic OS.
2021-07-18 16:55:57 +08:00
EricFromCanada
2ed324ebc0 use backticks around suggested input, flags, and binaries 2021-01-26 16:19:47 -05:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
rmnull
649e02ba3d
patchelf.rb writing in ELFShim 2020-08-27 22:50:34 +05:30
Markus Reiter
4304fa048e Document ELFShim. 2020-08-26 03:13:59 +02:00
Mike McQuaid
763bf6f699
Use vendored patchelf.rb. 2020-08-11 08:41:31 +01:00
rmnull
043719383b
remove code using patchelf, remove HOMEBREW_PATCHELF_RB var 2020-08-08 06:48:31 +05:30
rmnull
ce2eda5a26
remove PatchELF::Patcher refinements. 2020-07-29 09:38:15 +05:30
rmnull
e79eeb7560
Bug Fix: Don't search for needed libraries on non DYNAMIC ELFs. 2020-07-26 04:56:21 +05:30
rmnull
f92c7d30c1
let patchelf return nil on blank rpath 2020-07-25 01:07:52 +05:30
rmnull
d607528a5b
introduce ELFShim#rpath, refactor keg_relocate to use the same.
refines PatchELF #runpath, #rpath #soname #interpreter
to return nil.
let Brew hard exits on PatchELF::PatchError.

Co-authored-by: Shaun Jackman <sjackman@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-07-25 01:07:24 +05:30
rmnull
2ca03610e2
update patchelf.rb to '~> 1.1' in Gemfile. Replace instance variable access with call to .elf.
patcher.elf was introduced in gem release v1.1.0.
2020-07-14 04:30:29 +05:30
rmnull
35328ed535
[draft] refactoring keg_relocate to use ELFShim#interpreter instead of .with_interpreter? 2020-06-26 05:34:41 +05:30
rmnull
3f211415ca
don't warn "no interpreter found" for Shared ELF objects. 2020-06-22 01:24:03 +05:30
rmnull
486114282c
In ELFShim, #needed_libraries, #dynamic_elf? and #with_interpreter? check using patchelf gem.
Having HOMEBREW_PATCHELF_RB set in the ENV,
will conditionally install patchelf.rb gem,
use patchelf.rb in the above mentioned methods.
The installed vendored gems are listed in .gitignore
to maintain a clean state.
2020-06-19 21:23:57 +05:30
rmnull
69e1673a81 skip needed_libraries check when patchelf is the bottle being installed. 2020-05-15 05:36:49 +05:30
Issy Long
b87782ef7d
Auto-fix Style/UnpackFirst offenses 2019-10-13 16:04:34 +01:00
Cheng XU
2c82623318
keg_relocate: relocate the interpreter for elf files with INTERP header (Linux)
Some elf files (e.g. created by rust compiler) have INTERP header despite
their magic header denotes shared object instead of executable.

We should relocate the interpreter elf files as long as they have INTERP header.

This should fix the broken bottles for rust based formulae.
2019-07-18 15:22:43 +08:00
Cheng XU
3ab93b6e2b
elf: fix caching of dynamic_elf? 2019-07-18 15:22:43 +08:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Michka Popoff
5c068ef82c elf.rb: avoid corrupted elf files
Some elf files like unittest files or memory dumps may not be completely
readable by readelf.

Readelf will fail after the following message:
readelf: Warning: possibly corrupt ELF header - it has a non-zero program header offset, but no program headers

This patches avoid these files when there is a non zero offset but no
program headers
2019-03-09 17:16:36 +01:00
Shaun Jackman
9ef010738f needed_libraries: Fix cannot find section .dynamic
Fix the error `cannot find section .dynamic` when needed_libraries is
called on a static ELF executable.
2019-01-02 12:34:16 -08:00
EricFromCanada
20167e5f1b Adjust comments to tidy API docs output. 2018-10-18 21:42:43 -04:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Markus Reiter
2452b27866 Refactor ErrorDuringExecution. 2018-07-19 16:41:27 +02:00
Shaun Jackman
e5847b652f extend/pathname: Add os/linux/elf.rb 2017-12-03 16:22:51 -08:00