On 5/10/22 06:21 UTC, Mamoru TASAKA wrote:
Richard Shaw wrote on 2022/05/10 12:07:
> I'm working on some IIoT related packages in my COPR where I have a dynamic
> library linking to a static library and getting the following error:
> /usr/bin/ld:
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/libmqttc.a(mqtt.c.o):
> warning: relocation against `mqtt_fixed_header_rules' in read-only section
> `.text'
> /usr/bin/ld:
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../lib64/libmqttc.a(mqtt.c.o):
> relocation R_X86_64_PC32 against symbol `mqtt_fixed_header_rules' can not
> be used when making a shared object; recompile with -fPIC
>
> I added the following to the libmqttc library and verified -fPIC -pie is in
> the build flags[1] per the recommendation from the hardening page[2] but
> the error remains.
>
> Any ideas?
>
> Thanks,
> Richard
>
> [1]
>
https://download.copr.fedorainfracloud.org/results/hobbes1069/IIoT/fedora...
This log no longer seems to exist.
I was able to access it just now.
Some relevant lines are:
=====
[ 18%] Building C object CMakeFiles/mqttc.dir/src/mqtt.c.o
/usr/bin/gcc -DMQTT_USE_BIO -I/builddir/build/BUILD/MQTT-C-1.1.5/include -O2 -flto=auto
-ffat-lto-objects -fexceptions \
-g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-Wp,-D_GLIBCXX_ASSERTIONS \
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 \
-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
-fPIC -pie -MD -MT \
CMakeFiles/mqttc.dir/src/mqtt.c.o -MF CMakeFiles/mqttc.dir/src/mqtt.c.o.d -o
CMakeFiles/mqttc.dir/src/mqtt.c.o \
-c /builddir/build/BUILD/MQTT-C-1.1.5/src/mqtt.c
[ 27%] Linking C static library libmqttc.a
/usr/bin/cmake -P CMakeFiles/mqttc.dir/cmake_clean_target.cmake
/usr/bin/cmake -E cmake_link_script CMakeFiles/mqttc.dir/link.txt --verbose=1
/usr/bin/ar qc libmqttc.a CMakeFiles/mqttc.dir/src/mqtt_pal.c.o
CMakeFiles/mqttc.dir/src/mqtt.c.o
/usr/bin/ranlib libmqttc.a
=====
which confirms that "-fPIC -pie" was used when compiling mqtt.c into
CMakeFiles/mqttc.dir/src/mqtt.c.o .
Suggestion: extract mqtt.c.o from libmqttc.a, then run "readelf --all --wide mqtt.c.o
> foo"
and look in file foo for more information about:
relocation R_X86_64_PC32 against symbol `mqtt_fixed_header_rules'
Also, upstream should remedy complaints from the compiler:
=====
/builddir/build/BUILD/MQTT-C-1.1.5/examples/bio_publisher.c: In function 'main':
/builddir/build/BUILD/MQTT-C-1.1.5/examples/bio_publisher.c:47:5: warning:
'ERR_load_BIO_strings' is deprecated: \
Since OpenSSL 3.0 [-Wdeprecated-declarations]
47 | ERR_load_BIO_strings();
| ^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/openssl/cryptoerr.h:17,
from /usr/include/openssl/crypto.h:38,
from /usr/include/openssl/bio.h:30,
from /builddir/build/BUILD/MQTT-C-1.1.5/include/mqtt_pal.h:100,
from /builddir/build/BUILD/MQTT-C-1.1.5/include/mqtt.h:43,
from /builddir/build/BUILD/MQTT-C-1.1.5/examples/bio_publisher.c:10:
/usr/include/openssl/cryptoerr_legacy.h:31:27: note: declared here
31 | OSSL_DEPRECATEDIN_3_0 int ERR_load_BIO_strings(void);
| ^~~~~~~~~~~~~~~~~~~~
=====
and:
=====
/builddir/build/BUILD/MQTT-C-1.1.5/examples/simple_subscriber.c: In function
'main':
/builddir/build/BUILD/MQTT-C-1.1.5/examples/simple_subscriber.c:73:24: warning: passing
argument 2 of 'mqtt_init' makes pointer from integer without a cast
[-Wint-conversion]
73 | mqtt_init(&client, sockfd, sendbuf, sizeof(sendbuf), recvbuf,
sizeof(recvbuf), publish_callback);
| ^~~~~~
| |
| int
=====
plus several more int vs pointer conflicts.