python / cpython

The Python programming language
https://www.python.org
Other
63.42k stars 30.37k forks source link

Build failed when configure with `--enable-profiling` on FreeBSD #117452

Closed aisk closed 5 months ago

aisk commented 7 months ago

Bug report

Bug description:

Environment:

$ uname -a
FreeBSD f13 13.3-RELEASE FreeBSD 13.3-RELEASE releng/13.3-n257428-80d2b634ddf0 GENERIC amd64

$ cc --version
FreeBSD clang version 17.0.6 (https://github.com/llvm/llvm-project.git llvmorg-17.0.6-0-g6009708b4367)
Target: x86_64-unknown-freebsd13.3
Thread model: posix
InstalledDir: /usr/bin

Configuration:

./configure --enable-profiling --disable-ipv6, --disable-ipv6 is needed because it's reuired by --enable-profiling.

Error:

cc -pthread -pg    -o Programs/_freeze_module Programs/_freeze_module.o Modules/getpath_noop.o Modules/getbuildinfo.o  Parser/token.o Parser/pegen.o  Parser/pegen_errors.o  Parser/action_helpers.o  Parser/parser.o  Parser/string_parser.o  Parser/peg_api.o Parser/lexer/buffer.o  Parser/lexer/lexer.o  Parser/lexer/state.o  Parser/tokenizer/file_tokenizer.o  Parser/tokenizer/readline_tokenizer.o  Parser/tokenizer/string_tokenizer.o  Parser/tokenizer/utf8_tokenizer.o  Parser/tokenizer/helpers.o Parser/myreadline.o  Objects/abstract.o  Objects/boolobject.o  Objects/bytes_methods.o  Objects/bytearrayobject.o  Objects/bytesobject.o  Objects/call.o  Objects/capsule.o  Objects/cellobject.o  Objects/classobject.o  Objects/codeobject.o  Objects/complexobject.o  Objects/descrobject.o  Objects/enumobject.o  Objects/exceptions.o  Objects/genericaliasobject.o  Objects/genobject.o  Objects/fileobject.o  Objects/floatobject.o  Objects/frameobject.o  Objects/funcobject.o  Objects/iterobject.o  Objects/listobject.o  Objects/longobject.o  Objects/dictobject.o  Objects/odictobject.o  Objects/memoryobject.o  Objects/methodobject.o  Objects/moduleobject.o  Objects/namespaceobject.o  Objects/object.o  Objects/obmalloc.o  Objects/picklebufobject.o  Objects/rangeobject.o  Objects/setobject.o  Objects/sliceobject.o  Objects/structseq.o  Objects/tupleobject.o  Objects/typeobject.o  Objects/typevarobject.o  Objects/unicodeobject.o  Objects/unicodectype.o  Objects/unionobject.o  Objects/weakrefobject.o  Python/_warnings.o  Python/Python-ast.o  Python/Python-tokenize.o  Python/asdl.o  Python/assemble.o  Python/ast.o  Python/ast_opt.o  Python/ast_unparse.o  Python/bltinmodule.o  Python/brc.o  Python/ceval.o  Python/codecs.o  Python/compile.o  Python/context.o  Python/critical_section.o  Python/crossinterp.o  Python/dynamic_annotations.o  Python/errors.o  Python/flowgraph.o  Python/frame.o  Python/frozenmain.o  Python/future.o  Python/gc.o  Python/gc_free_threading.o  Python/gc_gil.o  Python/getargs.o  Python/getcompiler.o  Python/getcopyright.o  Python/getplatform.o  Python/getversion.o  Python/ceval_gil.o  Python/hamt.o  Python/hashtable.o  Python/import.o  Python/importdl.o  Python/initconfig.o  Python/instrumentation.o  Python/intrinsics.o  Python/jit.o  Python/legacy_tracing.o  Python/lock.o  Python/marshal.o  Python/modsupport.o  Python/mysnprintf.o  Python/mystrtoul.o  Python/object_stack.o  Python/optimizer.o  Python/optimizer_analysis.o  Python/optimizer_symbols.o  Python/parking_lot.o  Python/pathconfig.o  Python/preconfig.o  Python/pyarena.o  Python/pyctype.o  Python/pyfpe.o  Python/pyhash.o  Python/pylifecycle.o  Python/pymath.o  Python/pystate.o  Python/pythonrun.o  Python/pytime.o  Python/qsbr.o  Python/bootstrap_hash.o  Python/specialize.o  Python/structmember.o  Python/symtable.o  Python/sysmodule.o  Python/thread.o  Python/traceback.o  Python/tracemalloc.o  Python/getopt.o  Python/pystrcmp.o  Python/pystrtod.o  Python/pystrhex.o  Python/dtoa.o  Python/formatter_unicode.o  Python/fileutils.o  Python/suggestions.o  Python/perf_trampoline.o  Python/dynload_shlib.o        Modules/config.o  Modules/main.o  Modules/gcmodule.o  Modules/atexitmodule.o  Modules/faulthandler.o  Modules/posixmodule.o  Modules/signalmodule.o  Modules/_tracemalloc.o  Modules/_suggestions.o  Modules/_codecsmodule.o  Modules/_collectionsmodule.o  Modules/errnomodule.o  Modules/_io/_iomodule.o Modules/_io/iobase.o Modules/_io/fileio.o Modules/_io/bytesio.o Modules/_io/bufferedio.o Modules/_io/textio.o Modules/_io/stringio.o  Modules/itertoolsmodule.o  Modules/_sre/sre.o  Modules/_sysconfig.o  Modules/_threadmodule.o  Modules/timemodule.o  Modules/_typingmodule.o  Modules/_weakref.o  Modules/_abc.o  Modules/_functoolsmodule.o  Modules/_localemodule.o  Modules/_operator.o  Modules/_stat.o  Modules/symtablemodule.o  Modules/pwdmodule.o -ldl  -lutil -latomic                          -lm
ld: error: unable to find library -latomic
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

aisk commented 7 months ago

I think -latomic is not needed on x86-64. After some investigation, I found that when I remove the -latomic link flag in the Makefile manually, the compilation can proceed. However, it fails with:

./Programs/_freeze_module getpath ./Modules/getpath.py Python/frozen_modules/getpath.h
ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"

And run ./Programs/_freeze_module binary, I got the same error:

ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"

And then when checking the config.log, I found that:

configure:28439: checking whether libatomic is needed by <pyatomic.h>
configure:28489: cc -pthread -o conftest   -I. -I./Include  -pg  conftest.c -ldl  -lutil >&5
conftest.c:445:9: warning: 'PY_BUILTIN_HASHLIB_HASHES' macro redefined [-Wmacro-redefined]
  445 | #define PY_BUILTIN_HASHLIB_HASHES "md5,sha1,sha2,sha3,blake2"
      |         ^
conftest.c:444:9: note: previous definition is here
  444 | #define PY_BUILTIN_HASHLIB_HASHES /**/
      |         ^
1 warning generated.
configure:28489: $? = 0
configure:28489: ./conftest
ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"
configure:28489: $? = 1
configure: program exited with status 1

So it's the same issue that _freeze_module, and this leads to autoconf think the -latomic is needed.

aisk commented 7 months ago

Maybe this is a FreeBSD / clang issue, when compiling this simple file a.c:

#include <stdlib.h>
#include <stdio.h>

int main() {
        puts(getenv("PATH"));
}

with clang -pg a.c -lutil, the build result have the same error:

$ ./a.out
ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"
vstinner commented 5 months ago

Maybe this is a FreeBSD / clang issue

Can you report the issue to FreeBSD?

aisk commented 5 months ago

@vstinner Already reported: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269370

vstinner commented 5 months ago

@vstinner Already reported: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269370

Oh ok, thanks!

Since this issue is in FreeBSD and not Python, the bug was already reported to FreeBSD, I close the issue.