Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building with --so fails #467

Closed
shadeware opened this issue Jun 19, 2018 · 9 comments
Closed

building with --so fails #467

shadeware opened this issue Jun 19, 2018 · 9 comments

Comments

@shadeware
Copy link

shadeware commented Jun 19, 2018

Building seastar on ubuntu 18.04 with default gcc-7.3 fails with configure flag --so (and succeeds without it).

Error message:

[79/199] LINK build/debug/apps/seawreck/seawreck
FAILED: build/debug/apps/seawreck/seawreck 
g++  -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=vptr -DSEASTAR_ASAN_ENABLED -O0 -DSEASTAR_DEBUG -DSEASTAR_DEBUG_SHARED_PTR -DSEASTAR_DEFAULT_ALLOCATOR -DSEASTAR_THREAD_STACK_GUARDS -DSEASTAR_NO_EXCEPTION_HACK -DSEASTAR_SHUFFLE_TASK_QUEUE -I/coding/seastar/build/debug/gen -I/coding/seastar/build/debug/c-ares -Lbuild/debug -Lbuild/debug/fmt/fmt -g -Wl,--no-as-needed  -shared -fvisibility=hidden -Wno-attributes -pthread  -o build/debug/apps/seawreck/seawreck build/debug/apps/seawreck/seawreck.o build/debug/core/reactor.o build/debug/core/alien.o build/debug/core/execution_stage.o build/debug/core/systemwide_memory_barrier.o build/debug/core/fstream.o build/debug/core/posix.o build/debug/core/memory.o build/debug/core/resource.o build/debug/core/scollectd.o build/debug/core/metrics.o build/debug/core/app-template.o build/debug/core/thread.o build/debug/core/dpdk_rte.o build/debug/core/fsqual.o build/debug/core/linux-aio.o build/debug/util/conversions.o build/debug/util/program-options.o build/debug/util/log.o build/debug/util/backtrace.o build/debug/util/alloc_failure_injector.o build/debug/net/packet.o build/debug/net/posix-stack.o build/debug/net/net.o build/debug/net/stack.o build/debug/net/inet_address.o build/debug/rpc/rpc.o build/debug/rpc/lz4_compressor.o build/debug/core/exception_hacks.o build/debug/core/future-util.o build/debug/net/proxy.o build/debug/net/virtio.o build/debug/net/dpdk.o build/debug/net/ip.o build/debug/net/ethernet.o build/debug/net/arp.o build/debug/net/native-stack.o build/debug/net/ip_checksum.o build/debug/net/udp.o build/debug/net/tcp.o build/debug/net/dhcp.o build/debug/net/tls.o build/debug/net/dns.o build/debug/net/config.o -lboost_program_options -lboost_system -lboost_filesystem -lstdc++ -lm -lstdc++fs -lboost_thread -lcryptopp -lrt -lgnutls -lgnutlsxx -llz4 -lprotobuf -ldl -lgcc_s  -lyaml-cpp -lcares-seastar -lfmt -lasan -lubsan  
/usr/bin/x86_64-linux-gnu-ld: build/debug/fmt/fmt/libfmt.a(printf.cc.o): relocation R_X86_64_PC32 against symbol `_ZTVN3fmt17BasicMemoryWriterIcSaIcEEE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

I tried adding set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) at the start of fmt/CMakeLists.txt, and the building went further. It stopped at this next error:

[8/120] LINK build/debug/apps/httpd/httpd
FAILED: build/debug/apps/httpd/httpd 
g++  -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=vptr -DSEASTAR_ASAN_ENABLED -O0 -DSEASTAR_DEBUG -DSEASTAR_DEBUG_SHARED_PTR -DSEASTAR_DEFAULT_ALLOCATOR -DSEASTAR_THREAD_STACK_GUARDS -DSEASTAR_NO_EXCEPTION_HACK -DSEASTAR_SHUFFLE_TASK_QUEUE -I/coding/seastar/build/debug/gen -I/coding/seastar/build/debug/c-ares -Lbuild/debug -Lbuild/debug/fmt/fmt -g -Wl,--no-as-needed  -shared -fvisibility=hidden -Wno-attributes -pthread  -o build/debug/apps/httpd/httpd build/debug/apps/httpd/main.o build/debug/http/transformers.o build/debug/http/json_path.o build/debug/http/file_handler.o build/debug/http/common.o build/debug/http/routes.o build/debug/json/json_elements.o build/debug/json/formatter.o build/debug/http/matcher.o build/debug/http/mime_types.o build/debug/http/httpd.o build/debug/http/reply.o build/debug/http/api_docs.o build/debug/net/proxy.o build/debug/net/virtio.o build/debug/net/dpdk.o build/debug/net/ip.o build/debug/net/ethernet.o build/debug/net/arp.o build/debug/net/native-stack.o build/debug/net/ip_checksum.o build/debug/net/udp.o build/debug/net/tcp.o build/debug/net/dhcp.o build/debug/net/tls.o build/debug/net/dns.o build/debug/net/config.o build/debug/core/reactor.o build/debug/core/alien.o build/debug/core/execution_stage.o build/debug/core/systemwide_memory_barrier.o build/debug/core/fstream.o build/debug/core/posix.o build/debug/core/memory.o build/debug/core/resource.o build/debug/core/scollectd.o build/debug/core/metrics.o build/debug/core/app-template.o build/debug/core/thread.o build/debug/core/dpdk_rte.o build/debug/core/fsqual.o build/debug/core/linux-aio.o build/debug/util/conversions.o build/debug/util/program-options.o build/debug/util/log.o build/debug/util/backtrace.o build/debug/util/alloc_failure_injector.o build/debug/net/packet.o build/debug/net/posix-stack.o build/debug/net/net.o build/debug/net/stack.o build/debug/net/inet_address.o build/debug/rpc/rpc.o build/debug/rpc/lz4_compressor.o build/debug/core/exception_hacks.o build/debug/core/future-util.o -lboost_program_options -lboost_system -lboost_filesystem -lstdc++ -lm -lstdc++fs -lboost_thread -lcryptopp -lrt -lgnutls -lgnutlsxx -llz4 -lprotobuf -ldl -lgcc_s  -lyaml-cpp -lcares-seastar -lfmt -lasan -lubsan  
/usr/bin/x86_64-linux-gnu-ld: build/debug/libcares-seastar.a(ares_destroy.c.o): relocation R_X86_64_PC32 against symbol `ares_free' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

I added set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) at the start of c-ares/CMakeLists.txt as well, building finished without any more errors, but when I tried to compile and run simple apps they just kept crashing in random places, e.g. in fmt::internal::WidthHandler::report_unhandled_arg(). Looks like I violated ODR somehow with my naive hacking.

@denesb
Copy link
Contributor

denesb commented Jun 19, 2018

If I recall correctly we don't support building seastar as a shared library. That option is deprecated and should be removed.

@shadeware
Copy link
Author

That's too bad, my app must be a pluggable module (.so).
By the way, I learned about this flag in README-OSv.md (not that I'm targeting OSv, I just tried to gather as much info as possible).

@denesb
Copy link
Contributor

denesb commented Jun 19, 2018 via email

@nyh
Copy link
Contributor

nyh commented Jun 19, 2018 via email

@shadeware
Copy link
Author

Thank you for responses!

Linking libseastar.a to my .so doesn't seem to work. I can't tell exact linking flags since I'm using CMake and apparently there's nothing like compile_commands.json for linker, but when I try to add -Wl,--whole-archive,/coding/seastar/build/debug/libcares-seastar.a,--no-whole-archive to TARGET_LINK_LIBRARIES I get this compile-time error:

[13/13 0.5/sec] Linking CXX shared module libmod_myapp.so
FAILED: libmod_myapp.so
...
/usr/bin/x86_64-linux-gnu-ld: coding/seastar/build/debug/libcares-seastar.a(ares__close_sockets.c.o): relocation R_X86_64_PC32 against symbol `ares_free' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

and when I supply these flags to ${CMAKE_EXE_LINKER_FLAGS} (like the rest of pkg-config flags) it builds just fine but fails to load with error

_myapp.so: undefined symbol: _ZN7seastar17g_current_contextE

(Apparently this is thread-local variable).

Finally, one comment:
I don't know why you're trying to build a Seastar application as .so, but
if it's because you want
to run it alongside "normal" (non-Seastar) code, you'll have various
problems.

Yep, I'm planning to use seastar alongside normal code (so that seastar will handle I/O and other async/performance-sensitive stuff and pass results to normal code), and I intend to use -DSEASTAR_DEFAULT_ALLOCATOR and --overprovisioned.

@avikivity
Copy link
Member

avikivity commented Jun 19, 2018

Please also look at seastar::alien.

You'll need to adjust the c-ares configuration to have it produce relocatable code (-fpic). Alternatively, teach ./configure.y to use the system libcares.so instead of the bundled sources, if your system carries a new-enough version of c-ares.

@shadeware
Copy link
Author

It actually worked! I did the following steps:

  1. add set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) at the start of c-ares/CMakeLists.txt
  2. configure seastar with -fPIC (e.g. ./configure.py --disable-hwloc --cflags="-DSEASTAR_DEFAULT_ALLOCATOR -fPIC")
  3. ninja
  4. copy pkg-config's compile flags to CMAKE_CXX_FLAGS
  5. copy libs from pkg-config's linker flags to CMake's TARGET_LINK_LIBRARIES arguments (not ${CMAKE_EXE_LINKER_FLAGS})

So, my problem is resolved, but --so still remains in code and docs. Should I close this issue?

@denesb
Copy link
Contributor

denesb commented Jun 19, 2018 via email

@tchaikov
Copy link
Contributor

so support was added in #1484.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants