From: Jiri Slaby Subject: LTO: fix linking References: https://sigrok.org/bugzilla/show_bug.cgi?id=1433 With LTO, the trick to collect drivers does not work. Use linker script instead. --- Makefile.am | 15 ++++----------- src/driver_list_start.c | 33 --------------------------------- src/driver_list_stop.c | 33 --------------------------------- src/drivers.c | 2 +- src/libdrivers.ld | 9 +++++++++ 5 files changed, 14 insertions(+), 78 deletions(-) --- a/Makefile.am +++ b/Makefile.am @@ -173,22 +173,15 @@ libsigrok_la_SOURCES += \ src/scale/kern.c # Hardware drivers -noinst_LTLIBRARIES = src/libdrivers.la \ - src/libdrivers_head.la src/libdrivers_tail.la +noinst_LTLIBRARIES = src/libdrivers.la -src/libdrivers.o: src/libdrivers.la \ - src/libdrivers_head.la src/libdrivers_tail.la - $(AM_V_CCLD)$(LINK) src/libdrivers_head.la src/libdrivers.la \ - src/libdrivers_tail.la +src/libdrivers.o: src/libdrivers.la + $(AM_V_CCLD)$(LINK) src/libdrivers.la src/libdrivers.lo: src/libdrivers.o $(AM_V_GEN)echo "# Generated by libtool" > $@ $(AM_V_at)echo "pic_object='libdrivers.o'" >> $@ $(AM_V_at)echo "non_pic_object='libdrivers.o'" >> $@ -src_libdrivers_head_la_SOURCES = src/driver_list_start.c - -src_libdrivers_tail_la_SOURCES = src/driver_list_stop.c - src_libdrivers_la_SOURCES = src/drivers.c if HW_AGILENT_DMM @@ -604,7 +597,7 @@ src_libdrivers_la_SOURCES += \ endif libsigrok_la_LIBADD = src/libdrivers.lo $(SR_EXTRA_LIBS) $(LIBSIGROK_LIBS) -libsigrok_la_LDFLAGS = -version-info $(SR_LIB_VERSION) -no-undefined +libsigrok_la_LDFLAGS = -version-info $(SR_LIB_VERSION) -no-undefined -Wc,-T -Wc,src/libdrivers.ld library_includedir = $(includedir)/libsigrok library_include_HEADERS = \ --- a/src/driver_list_start.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the libsigrok project. - * - * Copyright (C) 2017 Marcus Comstedt - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include "libsigrok-internal.h" - -/* - * This marks the start of the driver list. This file must be linked - * before any actual drivers. - */ - -SR_PRIV const struct sr_dev_driver *sr_driver_list__start[] - __attribute__((section (SR_DRIVER_LIST_SECTION), - used, aligned(sizeof(struct sr_dev_driver *)))) - = { NULL /* Dummy item, as zero length arrays are not allowed by C99 */ }; --- a/src/driver_list_stop.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the libsigrok project. - * - * Copyright (C) 2017 Marcus Comstedt - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include "libsigrok-internal.h" - -/* - * This marks the end of the driver list. This file must be linked - * after any actual drivers. - */ - -SR_PRIV const struct sr_dev_driver *sr_driver_list__stop[] - __attribute__((section (SR_DRIVER_LIST_SECTION), - used, aligned(sizeof(struct sr_dev_driver *)))) - = { NULL /* Dummy item, as zero length arrays are not allowed by C99 */ }; --- a/src/drivers.c +++ b/src/drivers.c @@ -45,7 +45,7 @@ SR_API void sr_drivers_init(struct sr_co array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *)); #ifdef HAVE_DRIVERS - for (const struct sr_dev_driver **drivers = sr_driver_list__start + 1; + for (const struct sr_dev_driver **drivers = sr_driver_list__start; drivers < sr_driver_list__stop; drivers++) g_array_append_val(array, *drivers); #endif --- /dev/null +++ b/src/libdrivers.ld @@ -0,0 +1,9 @@ +SECTIONS +{ + __sr_driver_list : { + sr_driver_list__start = .; + *(__sr_driver_list) + sr_driver_list__stop = .; + } +} +INSERT AFTER .data;