This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: macOS builds expose stack_size option in LINKEDFOORSHARED and pyconfig
Type: behavior Stage:
Components: macOS Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, ronaldoussoren, xzcvczx
Priority: normal Keywords:

Created on 2018-10-11 18:11 by xzcvczx, last changed 2022-04-11 14:59 by admin.

Messages (7)
msg327545 - (view) Author: Simon Wells (xzcvczx) Date: 2018-10-11 18:11
if you didn't build python as a framework it adds sysconfig.get_config_vars('LINKFORSHARED') when you run 'python-config --ldflags' this resolves to

>>> sysconfig.get_config_var('LINKFORSHARED')
'-Wl,-stack_size,1000000  -framework CoreFoundation /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python'

the '-Wl,-stack_size' ldflag causes issues for clang with the error

"ld: -stack_size option can only be used when linking a main executable"
msg327546 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-11 19:05
Sorry, I can't reproduce that behavior.  What's more, that LINKFORSHARED value does not appear to be correct.  Have you tried doing a build from a clean build dicectory while rerunning ./configure?  What does your ./configure look like and do have any relevant env variables set?

>>> sysconfig.get_config_var('LINKFORSHARED')
'-Wl,-stack_size,1000000  -framework CoreFoundation'
msg327548 - (view) Author: Simon Wells (xzcvczx) Date: 2018-10-11 19:18
with a fresh 3.7.0 download

./configure --prefix=... --enable-shared
make -j5
make install

path/to/python3-config --ldflags
-lpython3.7m -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation
msg327549 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-11 19:40
Oh, you didn't mention --enable-shared!  But still it's not clear to me what problem your last results shows.  The value of python3-config --ldflags looks fine (ignore the repeated -framework CoreFoundation).  Are you still getting the "ld: -stack_size option can ...' message when you built the second time?  An installed --enable-shared build for me works just fine when using a non-standard prefix, i.e. a location where there is not already a Python3 installed.  So I still can't reproduce a problem.

By the way, I always recommend to avoid using the --enable-shared option for macOS builds; I know there are cases in the past where there *has* been build issues when building shared and there is already a Python installed at that prefix.  If possible, stick either a "plain Unix" build (no --enable-shared, no --enable-framework) or a framework build.  You're less likely to run into at first glance head-scratching building and linking issues.
msg327550 - (view) Author: Simon Wells (xzcvczx) Date: 2018-10-11 19:42
ah ok, sorry i wasn't clear at first, the issue isn't when building python its when building a library which depends on python in this case libxml2, which when given the --enable-python stuff uses "PYTHON_LIBS=`python$PYTHON_VERSION-config --ldflags`" and therefore is being given the -Wl,stack_size linker option which is not valid for non main executables according to the error produced from clang
msg327551 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-11 20:00
OK, now I finally get it, thanks, my fault.  Yes, we probably shouldn't be passing stack_size through to applications trying to embed Python in LINkFORSHARED and pyconfig.  That's an area that we don't test very well nor have tests for, AFAIK.  Would it possible for you to provide a simple example of building libxml2 that would allow us to more easily test this?
msg327552 - (view) Author: Simon Wells (xzcvczx) Date: 2018-10-11 20:24
oh the rabbit hole...

as i have other builds of python3.7 on my system i wanted to ensure it used the correct python and python-config (python 3.7 was built and installed into $HOME/Projects/python/inst/) as such its a rather convoluted configure command for libxml2

LDFLAGS="-L$HOME/Projects/python/inst/lib" PATH=/Users/simon/Projects/python/inst/bin/:$PATH ./configure --prefix=/Users/simon/Projects/python/inst/ --with-python=/Users/simon/Projects/python/inst/bin/python3 --with-python-install-dir=/Users/simon/Projects/python/inst/lib/python3.7/site-packages

the LDFLAGS envvar was required as python-config --ldflags also does not provide -L for the python libary

ld: library not found for -lpython3.7m

in config.log for libxml2 (PYTHON_LIBS which is the output of $HOME/Projects/python/python3-config --ldflags)
PYTHON_LIBS='-lpython3.7m -ldl -framework CoreFoundation -Wl,-stack_size,1000000 -framework CoreFoundation'

after LDFLAGS="..." is added

ld: -stack_size option can only be used when linking a main executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)

if you want more log lines please let me know but those should be the only relevant ones
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79141
2018-10-11 20:24:38xzcvczxsetmessages: + msg327552
2018-10-11 20:00:10ned.deilysettitle: python-config bad ldflags on macOS -> macOS builds expose stack_size option in LINKEDFOORSHARED and pyconfig
messages: + msg327551
versions: + Python 3.8
2018-10-11 19:42:55xzcvczxsetmessages: + msg327550
2018-10-11 19:40:00ned.deilysetmessages: + msg327549
2018-10-11 19:18:06xzcvczxsetmessages: + msg327548
2018-10-11 19:05:21ned.deilysetmessages: + msg327546
2018-10-11 18:11:21xzcvczxcreate