Skip to content
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

Add flags to superenv when building with glibc@2.13 #13568

Merged
merged 2 commits into from Jul 20, 2022

Conversation

danielnachun
Copy link
Member

This PR should fix most of the issues we were hitting in Homebrew/homebrew-portable-ruby#156. The root of the problem is that we can't mix headers from the system glibc with glibc@2.13 and the only way to guarantee this is to use -nostdinc and add the paths to the GCC headers with -isystem flags.

@BrewTestBot
Copy link
Member

Review period will end on 2022-07-19 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 17, 2022
@danielnachun danielnachun requested a review from Bo98 July 17, 2022 02:58
Comment on lines 44 to 46
gcc_include_dir, = Open3.capture2("#{cc} --print-file-name=include")
gcc_include_fixed_dir, = Open3.capture2("#{cc} --print-file-name=include-fixed")
paths << gcc_include_dir.strip << gcc_include_fixed_dir.strip
Copy link
Member

@Bo98 Bo98 Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gcc_include_dir, = Open3.capture2("#{cc} --print-file-name=include")
gcc_include_fixed_dir, = Open3.capture2("#{cc} --print-file-name=include-fixed")
paths << gcc_include_dir.strip << gcc_include_fixed_dir.strip
gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp
gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp
paths << gcc_include_dir << gcc_include_fixed_dir

This is more consistent with what we do elsewhere, assuming this works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a feeling that Open3 wasn't what we normally used. I'll test this in the Docker image before pushing to here.

@danielnachun danielnachun marked this pull request as draft July 17, 2022 23:17
@danielnachun
Copy link
Member Author

I'm marking this as a draft for now because I need to push commits to this that I can test in a VM but I don't want it to be merged until the testing is done.

@danielnachun danielnachun force-pushed the fix_glibc_2_13 branch 2 times, most recently from 82059ce to 989d8c1 Compare July 17, 2022 23:24
@danielnachun danielnachun marked this pull request as ready for review July 18, 2022 00:16
@danielnachun
Copy link
Member Author

There was just one minor issue I had to fix and now portable-ruby is building as expected.

@danielnachun danielnachun requested a review from Bo98 July 18, 2022 00:17
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Jul 18, 2022
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 18, 2022
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

@danielnachun
Copy link
Member Author

I know @Bo98 is busy with the ephemeral CI stuff right now but I would probably be good for him to have one more chance to look at this before merging given that this is tightly integrated with Homebrew/homebrew-portable-ruby#156.

@@ -326,6 +328,9 @@ class Cmd
end
args += rpath_flags("#{wl}-rpath=", rpath_paths)
args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path
# Use -rpath-link to make sure linker uses glibc@2.13 rather than the system glibc for indirect
# dependencies because -L will only handle direct dependencies.
args << "#{wl}-rpath-link=#{@opt}/glibc@2.13/lib" if @deps.include?("glibc@2.13")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change the -B a few lines above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would only matter if the user was building against glibc@2.13 on a host where brewed glibc was also installed. Given that we're only building against glibc@2.13 for relocatable bottles I don't think scenario should happen very often. We could probably accommodate this by just doing:

if @deps.include?("glibc@2.13")
  args << "-B#{@opt}/glibc@2.13/lib"
else
  args << "-B#{@opt}/glibc/lib"
end

If this sounds good I'll push the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you decide against pushing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect @danielnachun forgot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misunderstood your comment as wanting to merge as-is. We need to fix the issue below with unconditionally passing nostdinc so I will add this in a follow up PR.

@danielnachun danielnachun merged commit 8a2efb1 into Homebrew:master Jul 20, 2022
@@ -292,6 +292,8 @@ class Cmd
args.concat(optflags) unless runtime_cpu_detection?
args.concat(archflags)
args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0)
# Add -nostdinc when building against glibc@2.13 to avoid mixing system and brewed glibc headers.
args << "-nostdinc" if @deps.include?("glibc@2.13")
Copy link
Member

@Bo98 Bo98 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is gated to not run if we're not doing arg refurbishment (line 287).

I argue we actually want to do this unconditionally. I think this should be in cppflags instead, like the other -isystem flags. cppflags applies to all modes - including cpp invokations where neither cflags nor cxxflags are used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I tried this and it fixed the issue where the system headers were still being included seen here: Homebrew/homebrew-portable-ruby#156 (comment).

def homebrew_extra_isystem_paths
paths = []
# Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc.
if deps.any? { |d| d.name == "glibc@2.13" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielnachun I'd really like if we can extract all these references into a global constant or, if that doesn't allow superenv handling, a file somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically use a variable instead of hard coding glibc@2.13 so we only have to change it once? That does seem better for maintainability, I just have to see where I can define it that will be seen by both the superenv and the compiler shim.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielnachun I think the answer may be "nowhere" but at least if it's in two places with a comment in both that says to change them both at once that'd be better!

Copy link
Member

@carlocab carlocab Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our compiler shim doesn't load the Homebrew module, but we can definitely put this into a global constant which is passed to the compiler shim via an environment variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo environment variable, good idea 👍🏻

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the existing cccfg system

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could append_to_cccfg a character for whenever glibc@#{MIN_GLIBC_VERSION} is a dependency where MIN_GLIBC_VERSION is an environment variable we set once globally. The individual conditionals on glibc@2.13 being a dependency could then be replaced with conditional on HOMEBREW_CCCFG containing the relevant character, and the actual flags we set would also use #{MIN_GLIBC_VERSION} instead of the hardcoded 2.13 we're currently using. That should mean that whenever the version needs to be changed, we can just update MIN_GLIBC_VERSION and everything else will be updated automatically because it's not hardcoded.

Now that we know our strategy for handling glibc@2.13 works I can just test the refactoring by trying to build binutils as it will fail quickly if I mess something up. Thanks for the great suggestions for this!

@github-actions github-actions bot added the outdated PR was locked due to age label Aug 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2022
@danielnachun danielnachun deleted the fix_glibc_2_13 branch September 2, 2022 17:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants