Title: [`ctypes`][`linux`] `ctypes.util.find_library()` crash instead of return None · Issue #114257 · python/cpython · GitHub
Open Graph Title: [`ctypes`][`linux`] `ctypes.util.find_library()` crash instead of return None · Issue #114257 · python/cpython
X Title: [`ctypes`][`linux`] `ctypes.util.find_library()` crash instead of return None · Issue #114257 · python/cpython
Description: Bug report Bug description: The problem: ctypes.util.find_library() raises an exception on certain inputs when it cannot find it. Expected behavior: No exception, return None as advertised if it cannot find the library. Reproducer: # on ...
Open Graph Description: Bug report Bug description: The problem: ctypes.util.find_library() raises an exception on certain inputs when it cannot find it. Expected behavior: No exception, return None as advertised if it ca...
X Description: Bug report Bug description: The problem: ctypes.util.find_library() raises an exception on certain inputs when it cannot find it. Expected behavior: No exception, return None as advertised if it ca...
Opengraph URL: https://github.com/python/cpython/issues/114257
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[`ctypes`][`linux`] `ctypes.util.find_library()` crash instead of return None","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n# The problem:\r\n\r\n`ctypes.util.find_library()` raises an exception on certain inputs when it cannot find it.\r\n\r\n# Expected behavior:\r\n\r\nNo exception, return `None` as [advertised](https://docs.python.org/3/library/ctypes.html#ctypes.util.find_library) if it cannot find the library.\r\n\r\n# Reproducer:\r\n```python\r\n# on python 3.10, but same deal on other versions too\r\n\u003e\u003e\u003e import ctypes.util\r\n\u003e\u003e\u003e ctypes.util.find_library('libgomp')\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/path/to/lib/python3.10/ctypes/util.py\", line 351, in find_library\r\n _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))\r\n File \"/path/to/lib/python3.10/ctypes/util.py\", line 148, in _findLib_gcc\r\n if not _is_elf(file):\r\n File \"/path/to/lib/python3.10/ctypes/util.py\", line 100, in _is_elf\r\n with open(filename, 'br') as thefile:\r\nFileNotFoundError: [Errno 2] No such file or directory: b'liblibgomp.a'\r\n```\r\nNote that the crash does not occur if you put nonsense in:\r\n1. `find_library('asdadsas')` -\u003e OK\r\n2. `find_library('libasdasdasd')` -\u003e OK\r\n\r\nThe problem appears to be a bit more contrived. Python is attempting to parse the output from gcc, which in this case is:\r\n```\r\n/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o\r\n/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o\r\n/usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o\r\n/usr/bin/ld: cannot find -llibgomp: No such file or directory\r\n/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/12/libgomp.a use -l:libgomp.a or rename it to liblibgomp.a\r\n/usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a\r\n/usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so\r\n/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libgcc_s.so.1\r\n/usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a\r\ncollect2: error: ld returned 1 exit status\r\n```\r\nBut then the parser is getting confused trying to parse the useful diagnostic message mentioning `libgomp.a`.\r\n\r\nMachine details (from `platform.uname()`)\r\n```\r\nuname_result(system='Linux', node='iblis', release='6.5.0-14-generic', version='#14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2', machine='x86_64')\r\n```\r\n\r\n### CPython versions tested on:\r\n\r\n3.10, 3.11, 3.12\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-114394\n* gh-114444\n* gh-114445\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Jacobfaib","@type":"Person","name":"Jacobfaib"},"datePublished":"2024-01-18T18:35:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/114257/cpython/issues/114257"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:851f78e2-5eb0-4c1b-1830-63e7c1380e5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACC6:1A500C:1A2240:21C05B:696AD73C |
| html-safe-nonce | a234da41101b787b9aa2bea8fc25b4571e39b5b7f662648e11d0a327f307581b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0M2OjFBNTAwQzoxQTIyNDA6MjFDMDVCOjY5NkFENzNDIiwidmlzaXRvcl9pZCI6IjcwMjAzMjM5MjYyNjg2MzA4NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e351788685ce0a44c4f684a772714eb165ad5d3ff345df1bcf75e13edfea3e56 |
| hovercard-subject-tag | issue:2088850707 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/114257/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e3a9044c4a994b3c21c80344c60c0c7ac96c98b68b7232940a76236e73e19aa1/python/cpython/issues/114257 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e3a9044c4a994b3c21c80344c60c0c7ac96c98b68b7232940a76236e73e19aa1/python/cpython/issues/114257 |
| og:image:alt | Bug report Bug description: The problem: ctypes.util.find_library() raises an exception on certain inputs when it cannot find it. Expected behavior: No exception, return None as advertised if it ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Jacobfaib |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 524a93f2c1f36522a3b4be4c110467ee4172245d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width