-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
mac/formula_cellar_checks: check for flat namespace libraries #12225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There are at least five instances where a formula has libraries compiled with `-flat_namespace` due to a bug in detecting the macOS version (cf. Homebrew/homebrew-core#87103, Homebrew/homebrew-core#85974, Homebrew/homebrew-core#85973). I think it makes sense to check for this more generally. It is sometimes intentional, so I've added a check for an allowlist for those instances. Running this on the current `util-linux` bottle produces ❯ brew audit --strict util-linux util-linux: * Libraries were compiled with a flat namespace. This can cause linker errors due to name collisions, and is often due to a bug in detecting the macOS version. /usr/local/Cellar/util-linux/2.37.2/lib/libblkid.1.dylib /usr/local/Cellar/util-linux/2.37.2/lib/libfdisk.1.dylib /usr/local/Cellar/util-linux/2.37.2/lib/libsmartcols.1.dylib /usr/local/Cellar/util-linux/2.37.2/lib/libuuid.1.dylib Error: 1 problem in 1 formula detected Some things that still need to be done here: - fix this check for universal binaries - check if we want to restrict this audit check to newer versions of macOS - fix false positives (try `brew audit --strict llvm` and compare the output of `otool -hV` on the identified files) While we're here, let's fix the formatting of the output of these other audits (cf. #12217).
|
Review period will end on 2021-10-13 at 05:29:49 UTC. |
|
|
There was a typo that made it so that all libraries were being included in `flat_namespace_files`.
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work!
|
For reference, here is a list of formulae I have installed on Big Sur whose libraries have been compiled with Of these, I believe only |
|
Oh, here's another to-do. This check doesn't work for weird libraries like this one: The issue is that I think I just need to change the |
|
My run on Mojave: I'm a little concerned at how many exceptions there is going to be. Though equally, one can wonder why some of these need |
This is the type of thing I wonder if we just strip out with superenv (and allow exceptions). |
I'm concerned about this too. I'm not sure how to handle it though.
Agreed. My view is that flat namespaces are good for development and debugging (but then you can use |
Could do. I'd like to keep superenv exceptions to even more of a minimum as it indicates we are incorrectly stripping something. If it's just one or two that need it then it's probably ok. |
Oh, agreed, this just seems like the type of thing where Superenv stripping is going to be easier than patching all these build systems. |
|
I made a patch that emulates the libtool fix for this by removing diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc
index c629efa9e..d0f731830 100755
--- a/Library/Homebrew/shims/super/cc
+++ b/Library/Homebrew/shims/super/cc
@@ -208,6 +208,12 @@ class Cmd
args << arg unless tool =~ /^g..-4.[02]/
when /^-Wl,-z,defs/
# -Wl,-undefined,error is already the default
+ when "-Wl,-flat_namespace"
+ # remove arg
+ when "-Wl,-undefined"
+ arg2 = enum.next
+ arg2 = "-Wl,dynamic_lookup" if arg2 == "-Wl,suppress"
+ args << arg << arg2
when /^-W[alp],/, /^-Wno-/, "-Werror=implicit-function-declaration"
args << arg
when /^-W.*/ |
|
Review period ended. |
- Fix missing space - use `MachO::Utils.fat_magic?` - call `#flag?` consistently. Co-authored-by: Bo Anderson <mail@boanderson.me>
|
Let's try this. We can revert and/or strip the @Homebrew/core, if you see audit failures with the text feel free to ping/assign me. |
brew stylewith your changes locally?brew typecheckwith your changes locally?brew testswith your changes locally?There are at least five instances where a formula has libraries compiled
with
-flat_namespacedue to a bug in detecting the macOS version (cf.Homebrew/homebrew-core#87103, Homebrew/homebrew-core#85974,
Homebrew/homebrew-core#85973).
I think it makes sense to check for this more generally. It is
sometimes intentional, so I've added a check for an allowlist for
those instances. Running this on the current
util-linuxbottleproduces
Some things that still need to be done here:
fix this check for universal binariesfix false positives (trybrew audit --strict llvmand compare theoutput ofotool -hVon the identified files)While we're here, let's fix the formatting of the output of these other
audits (cf. #12217).
Here's some background on flat vs two-level namespaces: https://developer.apple.com/library/archive/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html#//apple_ref/doc/uid/TP40002850-BCIHJBBF