Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Compiling rock on ArchLinux x64 [pthread] #461

Closed
hangelwen opened this Issue Aug 15, 2012 · 17 comments

Comments

Projects
None yet
5 participants

The final linking step generated error:

gcc -std=gnu99 -Wall -g -I./libs/headers/ -Irock_tmp -O0 -w -DROCK_BUILD_DATE="2012-08-15" -DROCK_BUILD_TIME="18:19" -rdynamic .libs/source-linux64.a .libs/sdk-linux64.a .libs/source-linux64.a .libs/sdk-linux64.a -D__OOC_USE_GC__ -DGC_NO_THREAD_REDIRECTS -I.libs/source -I.libs/sdk .libs/NagaQueen.o -o bin/rock -lm -lpthread ./libs/linux64/libgc.a
./libs/linux64/libgc.a(pthread_support.o): In function GC_thr_init': (.text+0x5f0): undefined reference topthread_atfork'
collect2: error: ld returned 1 exit status
C compiler failed (got code 1), aborting compilation process

changing the -lpthread flag to -pthread fixed the problem

Collaborator

duckinator commented Aug 15, 2012

Hmm, strange. I'm in middle of migrating to systemd, so I'll try to take a look at this once I finish.

@hangelwen in case I can't reproduce it locally, could you put the full output on https://gist.github.com and paste the link here so I can at least try to narrow it down?

Thanks!

Owner

fredreichbier commented Aug 19, 2012

Happens for me too. This seems to have something to do with _REENTRANT, though I don't know why this hasn't happened to anyone before today.

Edit: Oh, and the output isn't really interesting, it happens with make rescue for me, here are the last lines:

Finished compiling for arch linux64
gcc -I c-source -I ../libs/headers/ -L/usr/local/lib -L/usr/pkg/lib -I/usr/local/include -I/usr/pkg/include -g -std=gnu99 -Wall -D__OOC_USE_GC__ -DGC_NO_THREAD_REDIRECTS -w -DROCK_BUILD_DATE="\"bootstrapped\"" -DROCK_BUILD_TIME="\"\"" c-source/source/rock/rock.o c-source/sdk/lang/Iterators.o c-source/sdk/lang/Buffer.o c-source/sdk/lang/Memory.o c-source/sdk/lang/VarArgs.o c-source/sdk/lang/Character.o c-source/sdk/lang/Format.o c-source/sdk/lang/Abstractions.o c-source/sdk/lang/BufferIterator.o c-source/sdk/lang/System.o c-source/sdk/lang/String.o c-source/sdk/lang/IO.o c-source/sdk/lang/Exception.o c-source/sdk/lang/types.o c-source/sdk/lang/Numbers.o c-source/sdk/threading/Thread.o c-source/sdk/threading/native/ThreadUnix.o c-source/sdk/threading/native/ThreadWin32.o c-source/sdk/native/win32/types.o c-source/sdk/native/win32/errors.o c-source/sdk/threading/native/MutexUnix.o c-source/sdk/threading/native/MutexWin32.o c-source/sdk/threading/native/ThreadLocalUnix.o c-source/sdk/structs/HashMap.o c-source/sdk/structs/ArrayList.o c-source/sdk/structs/List.o c-source/sdk/math/Random.o c-source/sdk/os/Time.o c-source/sdk/threading/native/ThreadLocalWin32.o c-source/sdk/structs/Stack.o c-source/sdk/structs/LinkedList.o c-source/sdk/os/Terminal.o c-source/sdk/os/FileDescriptor.o c-source/sdk/os/unistd.o c-source/source/rock/frontend/CommandLine.o c-source/sdk/io/File.o c-source/sdk/io/FileReader.o c-source/sdk/io/Reader.o c-source/sdk/io/FileWriter.o c-source/sdk/io/Writer.o c-source/sdk/os/Pipe.o c-source/sdk/os/native/PipeUnix.o c-source/sdk/os/native/PipeWin32.o c-source/sdk/io/BufferWriter.o c-source/sdk/io/BufferReader.o c-source/sdk/io/native/FileWin32.o c-source/sdk/io/native/FileUnix.o c-source/sdk/text/StringTokenizer.o c-source/sdk/os/Process.o c-source/sdk/os/PipeReader.o c-source/sdk/os/native/ProcessUnix.o c-source/sdk/os/Env.o c-source/sdk/os/wait.o c-source/sdk/os/native/ProcessWin32.o c-source/source/rock/RockVersion.o c-source/source/rock/frontend/Help.o c-source/source/rock/frontend/Token.o c-source/source/rock/frontend/BuildParams.o c-source/source/rock/frontend/compilers/AbstractCompiler.o c-source/source/rock/frontend/PathList.o c-source/source/rock/utils/ShellUtils.o c-source/source/rock/middle/Module.o c-source/sdk/text/EscapeSequence.o c-source/sdk/math.o c-source/sdk/structs/OrderedMultiMap.o c-source/sdk/structs/MultiMap.o c-source/source/rock/frontend/AstBuilder.o c-source/source/rock/utils/FileUtils.o c-source/source/rock/middle/tinker/Errors.o c-source/source/rock/middle/tinker/Trail.o c-source/source/rock/middle/Node.o c-source/source/rock/middle/Visitor.o c-source/source/rock/middle/Return.o c-source/source/rock/middle/Statement.o c-source/source/rock/middle/Expression.o c-source/source/rock/middle/Type.o c-source/source/rock/backend/cnaughty/AwesomeWriter.o c-source/source/rock/io/TabbedWriter.o c-source/source/rock/middle/Declaration.o c-source/source/rock/middle/VariableDecl.o c-source/source/rock/middle/TypeDecl.o c-source/source/rock/middle/ClassDecl.o c-source/source/rock/middle/Cast.o c-source/source/rock/middle/FunctionCall.o c-source/source/rock/middle/FunctionDecl.o c-source/source/rock/middle/Argument.o c-source/source/rock/middle/VariableAccess.o c-source/source/rock/middle/BinaryOp.o c-source/source/rock/middle/OperatorDecl.o c-source/source/rock/middle/tinker/Resolver.o c-source/source/rock/middle/Import.o c-source/source/rock/middle/tinker/Response.o c-source/source/rock/middle/tinker/Tinkerer.o c-source/source/rock/middle/CoverDecl.o c-source/source/rock/middle/AddressOf.o c-source/source/rock/middle/ArrayAccess.o c-source/source/rock/middle/ArrayCreation.o c-source/source/rock/middle/Scope.o c-source/source/rock/middle/FuncType.o c-source/source/rock/middle/BaseType.o c-source/source/rock/middle/InterfaceDecl.o c-source/source/rock/middle/NamespaceDecl.o c-source/source/rock/middle/Version.o c-source/source/rock/middle/ControlStatement.o c-source/source/rock/middle/NullLiteral.o c-source/source/rock/middle/Literal.o c-source/source/rock/middle/PropertyDecl.o c-source/source/rock/middle/Block.o c-source/source/rock/middle/Tuple.o c-source/source/rock/middle/TypeList.o c-source/source/rock/middle/StructLiteral.o c-source/source/rock/middle/EnumDecl.o c-source/source/rock/middle/IntLiteral.o c-source/source/rock/middle/FloatLiteral.o c-source/source/rock/middle/InlineContext.o c-source/source/rock/middle/algo/autoReturn.o c-source/source/rock/middle/Conditional.o c-source/source/rock/middle/If.o c-source/source/rock/middle/Else.o c-source/source/rock/middle/StringLiteral.o c-source/source/rock/middle/Dereference.o c-source/source/rock/middle/CommaSequence.o c-source/source/rock/middle/Ternary.o c-source/source/rock/middle/ArrayLiteral.o c-source/source/rock/middle/InterfaceImpl.o c-source/source/rock/middle/Addon.o c-source/source/rock/middle/While.o c-source/source/rock/middle/Foreach.o c-source/source/rock/middle/RangeLiteral.o c-source/source/rock/middle/CharLiteral.o c-source/source/rock/middle/BoolLiteral.o c-source/source/rock/middle/Parenthesis.o c-source/source/rock/middle/Comparison.o c-source/source/rock/middle/UnaryOp.o c-source/source/rock/middle/Match.o c-source/source/rock/middle/FlowControl.o c-source/source/rock/middle/Include.o c-source/source/rock/middle/Use.o c-source/source/rock/middle/UseDef.o c-source/source/rock/middle/CallChain.o c-source/source/rock/middle/Try.o c-source/source/rock/frontend/compilers/Gcc.o c-source/source/rock/frontend/compilers/BaseCompiler.o c-source/source/rock/frontend/compilers/Clang.o c-source/source/rock/frontend/compilers/Icc.o c-source/source/rock/frontend/compilers/Tcc.o c-source/source/rock/frontend/drivers/Driver.o c-source/source/rock/frontend/pkgconfig/PkgInfo.o c-source/source/rock/frontend/pkgconfig/PkgConfigFrontend.o c-source/source/rock/frontend/drivers/CombineDriver.o c-source/source/rock/frontend/Target.o c-source/source/rock/backend/cnaughty/CGenerator.o c-source/source/rock/io/CachedFileWriter.o c-source/source/rock/backend/cnaughty/Skeleton.o c-source/source/rock/backend/cnaughty/FunctionDeclWriter.o c-source/source/rock/backend/cnaughty/ClassDeclWriter.o c-source/source/rock/backend/cnaughty/VersionWriter.o c-source/source/rock/backend/cnaughty/ControlStatementWriter.o c-source/source/rock/backend/cnaughty/ModuleWriter.o c-source/source/rock/backend/cnaughty/CoverDeclWriter.o c-source/source/rock/backend/cnaughty/TypeWriter.o c-source/source/rock/backend/cnaughty/FunctionCallWriter.o c-source/source/rock/backend/cnaughty/CastWriter.o c-source/source/rock/backend/cnaughty/InterfaceDeclWriter.o c-source/source/rock/frontend/drivers/SequenceDriver.o c-source/source/rock/frontend/drivers/Archive.o c-source/source/rock/frontend/drivers/MakeDriver.o c-source/source/rock/frontend/drivers/DummyDriver.o c-source/source/rock/backend/json/JSONGenerator.o c-source/sdk/structs/Bag.o c-source/sdk/structs/HashBag.o c-source/sdk/text/json/Generator.o c-source/sdk/text/json/Parser.o c-source/sdk/io/StringReader.o c-source/source/rock/backend/explain/ExplanationGenerator.o   c-source/source/rock/frontend/NagaQueen.c -o ../bin/c_rock -lm -lpthread  ../libs/linux64/libgc.a
../libs/linux64/libgc.a(pthread_support.o): In function `GC_thr_init':
(.text+0x5f0): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
make[2]: *** [link] Error 1
make[2]: Leaving directory `/home/fred/dev/ooc/rock/build'
make[1]: *** [bootstrap] Error 2
make[1]: Leaving directory `/home/fred/dev/ooc/rock'
make: *** [rescue] Error 2
Collaborator

shamanas commented Aug 19, 2012

@fredreichbier Does changing -lpthread to -pthread work for you too?

Owner

fredreichbier commented Aug 19, 2012

Eyyup! It seems to work with -lpthread too if I make it link libgc dynamically instead of statically (by changing the Makefile GC_PATH variable), but don't ask me why!

Collaborator

duckinator commented Aug 19, 2012

Hey, sorry I didn't get on this. Been kinda busy. Still am.

@shamanas @fredreichbier if you guys need me, you can @mention me but don't expect a super-quick answer like I usually do. :P

Owner

fredreichbier commented Aug 28, 2012

So I tried it again, and it seems like this can be fixed in two ways:

  1. Linking the gc dynamically by specifying --gc=dynamic
  2. Linking the gc statically, but fixing the command line. Disregard what I said above, it doesn't seem to have anything to do with _REENTRANT, but rather with the order of arguments passed to the linker. According to this page, when linking statically, the objects files with unresolved symbols have to be passed to the linker before passing the files providing these symbols. The current link target looks like this:
link: ${OBJECT_FILES}
    ${CC} ${CFLAGS} ${OBJECT_FILES}  c-source/source/rock/frontend/NagaQueen.c -o ${EXECUTABLE} -lm  -lpthread ${GC_PATH}

Since libgc.a references several pthread symbols (the first one is pthread_atfork), but -lpthread is passed before libgc.a, the linker throws the error.
So, we can either pass -lpthread after ${GC_PATH} or we use -pthread, which seems to add -lpthread to the end of the linker command line anyway.

But I still don't why this only occurs now. Ideas?

Member

nddrylliog commented Aug 28, 2012

@fredreichbier Additional info: it still compiles and link fine on Ubuntu 12.04 - apparently onlyr Archfags (sorry) have problems with it.

Member

nddrylliog commented Aug 28, 2012

Anyway, rock is supposed to produce correct Makefiles - if we need to make it provide GC_PATH before, it's not a big deal.

Collaborator

duckinator commented Aug 28, 2012

If it works on Ubuntu but not ArchLinux, I imagine it's related to the gcc version. If moving ${GC_PATH} does the trick without breaking it elsewhere I imagine that'd be the best approach.

EDIT: If I use the same sentence structure too many times, I imagine someone will start twitching. _hides_

Owner

fredreichbier commented Aug 28, 2012

Okay, this is the second time I'm correcting myself, I can't help it! So...
Since it's working in Ubuntu 12.04, as @duckinator said, it had to have something to do with versions, my current guess is that it's the GC. Ubuntu 12.04 ships boehm gc 7.1, while Archfag (<3) Linux has 7.2. It seems like 7.1 doesn't even use pthread_atfork: nm libgc.a | grep pthread_atfork shows nothing on Ubuntu (at least with the .a I tested, would be nice if someone could confirm), but shows U pthread_atfork on Arch. So gc 7.1 doesn't seem to reference pthread_atfork, which is why we don't get this error in Ubuntu and why we didn't get it on Arch before.
And now to the issue of linker arguments order. Looking in /lib/libpthread.so (as described here), pthread_atfork is actually part of a static library libpthread_nonshared.a, which means that this library is linked statically, implicity, which means that the order of linker arguments matters here (we need to pass libgc.a before -lpthread since we're implicity linking a static library providing pthread_atfork). I think that should be it. Does this make sense? :D

To the fixing: At least gcc and clang seem to support the -pthread option. tcc has experimental support, but it's not in 0.9.25. What do you think about using -pthread? It seems to be a better idea in terms of platform independency.

Collaborator

shamanas commented Aug 29, 2012

I think passing -pthread is the way to go (tcc is a non-issue, at the moment anyway, as it does not compile the C99 code rock-0.9.x generates)

Member

nddrylliog commented Nov 18, 2012

Is this still an issue? Or do we use -pthread by default now? If it's still not fixed, can it be in for 0.9.4?

Collaborator

shamanas commented Nov 18, 2012

Will be fixed for 0.9.4

Collaborator

shamanas commented Nov 19, 2012

Actually, -pthread is not present in mingw-gcc, so what am I to do?
(Maybe use -pthread on everything but Windows and no flag at all on windows? Or maybe just change the order that we link the GC and pthreads )

Collaborator

shamanas commented Nov 19, 2012

@nddrylliog I'm really hesitant to remove the -lpthread flag on windows. I mean, the GC could have been built with a win32 version of pthreads after all...

Member

nddrylliog commented Nov 19, 2012

@shamanas So... -lpthread on Windows and -pthread everywhere else?

Collaborator

shamanas commented Nov 19, 2012

@nddrylliog Ok, merging my changes then
@fredreichbier or @hangelwen, can you please make sure rock now builds fine?

@shamanas shamanas closed this in 226d754 Nov 19, 2012

shamanas added a commit that referenced this issue Nov 19, 2012

Merge pull request #476 from shamanas/refFunc
Change order that the GC and pthreads are linked in. Should fix #461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment