Re: Static library linking error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 10, 2022 at 3:09 AM John Reiser <jreiser@xxxxxxxxxxxx> wrote:
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-rawhide-x86_64/04386803-mqtt-c/builder-live.log.gz
>
> 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 .

I misread the hardening page but I got the same error without -fPIC -pie...

 
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'

I'll take a look, but this is one place where building in mock sucks... I can shell in to the chroot but not everything "works" exactly the same, especially vim, which I have to manually install :) 


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.

Yes, I'm surprised I ran into so many because they run with -Werror but they are probably using a much older gcc.

Thanks,
Richard 
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux