bazel-contrib / bazel-contrib/rules_foreign_cc

configure_make with --force_pic option forces -pie

Open
#1,360 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
737
Forks
270
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I'm trying to compile openssl-1.1.1q shared libraries with configure_make under rules_foreign_cc version 0.9.0. The `BUILD.bazel` file I'm using is
```
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//visibility:private"],
)

configure_make(
name = "openssl",
args = ["-j $(nproc)"],
configure_command = "config",
configure_in_place = True,
configure_options = [
"enable-ssl3",
"enable-ssl3-method",
"shared",
],
lib_source = "@openssl//:srcs",
out_shared_libs = [
"libcrypto.so.1.1",
"libssl.so.1.1",
],
copts = [
"-fPIC",
],
visibility = ["//visibility:public"],
)
```

My project root bazelrc file has force_pic option on
```
build --force_pic
```

and I'm having the following error when building libcrypto.so
```
/lib/../lib64/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:755: libcrypto.so] Error 1
```

The actual build command shown in the logs is:
```
/usr/local/gcc-7.3.0/bin/gcc -fPIC -pthread -m64 -Wa,--noexecstack -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -D_FORTIFY_SOURCE=1 -DNDEBUG -ffunction-sections -fdata-sections -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted -DBAZEL_COMPILE -Wextra -fstack-protector-strong -g -fPIC -L. -Wl,-znodelete -shared -Wl,-Bsymbolic \
-pie \
-fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/local/gcc-7.3.0/bin -pass-exit-codes -Wl,--gc-sections -lstdc++ -lm -Wl,-z,relro,-z,now,-z,noexecstack -Wl,-soname=libcrypto.so.1.1 \
-o libcrypto.so.1.1 ........
```

If I build without `force_pic` it worked like charm, the only difference in build command is `-pie`. In this case is there a way I can make it work with `--force_pic` on, for example remove "-pie" in linkopts?

Thanks

Contributor guide

Open the contributing guide

Research direction

Start with the configure_make rule and the generated link command from the provided BUILD.bazel example. Reproduce the OpenSSL build with --force_pic and compare it with the build without that option. Done means the shared libraries build successfully without the unwanted -pie flag while retaining position-independent code.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.