Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127604: Optimize -ldl usage on platforms that use dlopen for libFFI.#133081

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
freakboy3742 merged 2 commits intopython:mainfromfreakboy3742:apple-ldl
Apr 30, 2025

Conversation

freakboy3742
Copy link
Contributor

@freakboy3742freakboy3742 commentedApr 28, 2025
edited by bedevere-appbot
Loading

#133040 modified the handling of-ldl, resulting in multiple copies of-ldl being included in link commands.

#133071 modified this handling to minimise a lot of those usages; but on platforms that usedlopen() (macOS and iOS), there was still some duplicated use. This PR cleans up that usage.

@freakboy3742
Copy link
ContributorAuthor

!buildbot iOS

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@freakboy3742 for commit297f242 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133081%2Fmerge

The command will test the builders whose names match following regular expression:iOS

The builders matched are:

  • iOS ARM64 Simulator PR

@freakboy3742
Copy link
ContributorAuthor

freakboy3742 commentedApr 28, 2025
edited
Loading

Nope... looks like that hasn't done it. I'll take another look in the morning if nobody beats me to it.

picnixz
picnixz previously approved these changesApr 28, 2025
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

It looks fine and I'm pretty sure there is a cleaner and alternative way to do it but I'm also pretty sure that it would require more steps and a more complicate configuration so I think we should live with this first.

More generally, I think we need to have a function that cleans up the flags to remove duplicate ones.

@picnixz
Copy link
Member

Nope... looks like that hasn't done it. I'll take another look in the morning if nobody beats me to it.

Wait how come? then where is the one coming from...?

@picnixzpicnixz dismissed theirstale reviewApril 28, 2025 12:14

Apparently it doesn't work.

@picnixz
Copy link
Member

Actually, it looks like it worked because before we had (in the "Compile build Python" step):

ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'

and now we have

ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'ld: warning: ignoring duplicate libraries: '-ldl'

So two warnings go eliminated. It remains to check what the others are. We also have 2 warnings less in the "Compile host Python" step.

@picnixz
Copy link
Member

Note that the duplicate-ldl appear in only one command:

gcc -ldl    -o _bootstrap_python Modules/getbuildinfo.o [...] \Programs/_bootstrap_python.o Modules/getpath.o -ldl  -framework CoreFoundation

@freakboy3742
Copy link
ContributorAuthor

@picnixz After a little more digging, Ithink I've found the source of the problem.

The code added by#133040 is adding-ldl to the top-levelLDFLAGS. This effectively means that every link command gets-ldl injected.

Apple platforms then do a similar check; appending toLIBFFI_LDFLAGS. The initial form of this PR removes that addition, removing most of the duplicate library usage if theLDFLAGS version was used, avoiding most of the duplicates.

However there's alsothis check fordl on L3714, which looks for dlopen; on success, this adds-ldl toLIBS.

Having-ldl in bothLIBS andLDFLAGS leads to the the remaining handful of duplicated cases, becauseLDFLAGS ends up being part ofPY_LDFLAGS, which is part ofPY_CORE_LDFLAGS - and many of the places that includePY_CORE_LDFLAGS also includeLIBS.

So - one fix is to move theLDFLAGS addition until after L3714, and only append toLDFLAGS if thedl check failed. I've done that in the updated version of the PR, but I'm not completely convinced that's the right approach.

It seems like the pre-existing check fordl (that is documented to exist to support SunOS/Solaris, but is also picked up by macOS/iOS) seems incomplete/incompatible with how it's being added in service offaulthandler. It feels like it might be more appropriate to add-ldl only to the linking commands forfaulthandler - which, by the Makefile, would beMODULE_FAULTHANDLER_LDFLAGS - but at that point I'm into the weeds of autoconf macros and it's not clear to me how that would be injected cleanly.

@freakboy3742
Copy link
ContributorAuthor

!buildbot iOS

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@freakboy3742 for commitf6a117a 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133081%2Fmerge

The command will test the builders whose names match following regular expression:iOS

The builders matched are:

  • iOS ARM64 Simulator PR

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

It works but I don't know if there is a better autoconf-way to do it

dnl only add -ldl to LDFLAGS if it isn't already part of LIBS (GH-133081)
AS_VAR_IF([ac_cv_require_ldl], [yes], [
AS_VAR_IF([ac_cv_lib_dl_dlopen], [yes], [], [
AS_VAR_APPEND([LDFLAGS], [" -ldl"])
Copy link
Member

Choose a reason for hiding this comment

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

Would autoconf be smart enough if we were to just use AC_CHECK_LIB for dladdr1 as we did for dlopen in that it wouldn't readd the -ldl flag or is it the only way to write these extra checks?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Honestly, I don't know - I know enough autoconf to get by, but not much more.

Unfortunately, I don't have ready access to a development platform that would use thedladdr1 check (at least, I don't think I do), so it's difficult for me to experiment with this.

My concern would be whether it would add the flag toLIBS orLDFLAGS though - if it's added toLIBS, we'll be back in the same situation as before. Based on what I'm seeing in otherAC_CHECK_LIB usage, it looks like it would get added toLIBS by default, and any strategy that got it intoLDFLAGS would essentially be no better thanAS_VAR_APPEND.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Let's keep it that way (it works, it's a bit fragile, but we'll manage if there are issues in the future)

freakboy3742 reacted with thumbs up emoji
@freakboy3742freakboy3742 merged commit58a0f40 intopython:mainApr 30, 2025
46 checks passed
@freakboy3742freakboy3742 deleted the apple-ldl branchApril 30, 2025 08:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz approved these changes

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland is a code owner

@corona10corona10Awaiting requested review from corona10corona10 is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@freakboy3742@bedevere-bot@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp