[XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script

Anthony PERARD posted 1 patch 1 year, 2 months ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230216141007.21827-1-anthony.perard@citrix.com
tools/libs/libs.mk | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
[XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script
Posted by Anthony PERARD 1 year, 2 months ago
Unfortunatly, --default-symver doesn't work with LLVM's LD, LLD.
Instead, we will generate a temporary version-script.

In order to allow regenerating the script, we'll have a different
filename. In order to check if the content is up-to-date, we'll always
generated it and compare.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Fixes: 98d95437edb6 ("libs: Fix auto-generation of version-script for unstable libs")
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---

Notes:
    v2:
    - Replace "VERS" by "lib$(LIB_FILE_NAME)" in the new .map file.
    - Set version-script to lib$(LIB_FILE_NAME).map.tmp, like the filename
      used by the library binaries. (instead of libxen$(LIBNAME).map.tmp)
    - Write temporary file in the same directory as the target (in case the
      target is in a different directory)
    - remove temporary file generated by the new rule, in case it isn't
      removed by move-if-changed..
    - use ?= to set version-script, this mean that version-script has now a
      deferred expansion instead of immediate, hoping nothing break.
    
    CC: Jan Beulich <jbeulich@suse.com>

 tools/libs/libs.mk | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 0e4b5e0bd0..ffb6c9f064 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -5,6 +5,7 @@
 #   MAJOR:   major version of lib (Xen version if empty)
 #   MINOR:   minor version of lib (0 if empty)
 #   version-script: Specify the name of a version script to the linker.
+#     (If empty, a temporary one for unstable library is created)
 
 LIBNAME := $(notdir $(CURDIR))
 
@@ -27,6 +28,8 @@ ifneq ($(nosharedlibs),y)
 TARGETS += lib$(LIB_FILE_NAME).so
 endif
 
+version-script ?= lib$(LIB_FILE_NAME).map.tmp
+
 PKG_CONFIG ?= $(LIB_FILE_NAME).pc
 PKG_CONFIG_NAME ?= Xen$(LIBNAME)
 PKG_CONFIG_DESC ?= The $(PKG_CONFIG_NAME) library for Xen hypervisor
@@ -72,6 +75,10 @@ headers.lst: FORCE
 	@{ set -e; $(foreach h,$(LIBHEADERS),echo $(h);) } > $@.tmp
 	@$(call move-if-changed,$@.tmp,$@)
 
+lib$(LIB_FILE_NAME).map.tmp: FORCE
+	echo 'lib$(LIB_FILE_NAME)_$(MAJOR).$(MINOR) { global: *; };' >$(@D)/.$(@F)
+	$(call move-if-changed,$(@D)/.$(@F),$@)
+
 lib$(LIB_FILE_NAME).a: $(OBJS-y)
 	$(AR) rc $@ $^
 
@@ -81,7 +88,7 @@ lib$(LIB_FILE_NAME).so.$(MAJOR): lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR): $(PIC_OBJS) $(version-script)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,lib$(LIB_FILE_NAME).so.$(MAJOR) -Wl,$(if $(version-script),--version-script=$(version-script),--default-symver) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,lib$(LIB_FILE_NAME).so.$(MAJOR) -Wl,--version-script=$(version-script) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS) $(APPEND_LDFLAGS)
 
 # If abi-dumper is available, write out the ABI analysis
 ifneq ($(ABI_DUMPER),)
@@ -120,7 +127,7 @@ TAGS:
 clean::
 	rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
 	rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
-	rm -f headers.chk headers.lst
+	rm -f headers.chk headers.lst lib*.map.tmp .*.tmp
 
 .PHONY: distclean
 distclean: clean
-- 
Anthony PERARD
Re: [XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script
Posted by Andrew Cooper 1 year, 2 months ago
On 16/02/2023 2:10 pm, Anthony PERARD wrote:
> diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
> index 0e4b5e0bd0..ffb6c9f064 100644
> --- a/tools/libs/libs.mk
> +++ b/tools/libs/libs.mk
> @@ -120,7 +127,7 @@ TAGS:
>  clean::
>  	rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
>  	rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
> -	rm -f headers.chk headers.lst
> +	rm -f headers.chk headers.lst lib*.map.tmp .*.tmp

Doesn't *.tmp cover lib*.map.tmp ?

Also the subject still needs a FreeBSD->LLVM fix.

Both can be fixed on commit.

~Andrew
Re: [XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script
Posted by Anthony PERARD 1 year, 2 months ago
On Thu, Feb 16, 2023 at 04:50:09PM +0000, Andrew Cooper wrote:
> On 16/02/2023 2:10 pm, Anthony PERARD wrote:
> > diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
> > index 0e4b5e0bd0..ffb6c9f064 100644
> > --- a/tools/libs/libs.mk
> > +++ b/tools/libs/libs.mk
> > @@ -120,7 +127,7 @@ TAGS:
> >  clean::
> >  	rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
> >  	rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
> > -	rm -f headers.chk headers.lst
> > +	rm -f headers.chk headers.lst lib*.map.tmp .*.tmp
> 
> Doesn't *.tmp cover lib*.map.tmp ?

There is no "*.tmp" on this command line, but there is ".*.tmp".

> Also the subject still needs a FreeBSD->LLVM fix.

Sounds good.

> Both can be fixed on commit.

If you only fix the subject, then that's fine by me.

Thanks,

-- 
Anthony PERARD
Re: [XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script
Posted by Andrew Cooper 1 year, 2 months ago
On 16/02/2023 4:55 pm, Anthony PERARD wrote:
> On Thu, Feb 16, 2023 at 04:50:09PM +0000, Andrew Cooper wrote:
>> On 16/02/2023 2:10 pm, Anthony PERARD wrote:
>>> diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
>>> index 0e4b5e0bd0..ffb6c9f064 100644
>>> --- a/tools/libs/libs.mk
>>> +++ b/tools/libs/libs.mk
>>> @@ -120,7 +127,7 @@ TAGS:
>>>  clean::
>>>  	rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
>>>  	rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
>>> -	rm -f headers.chk headers.lst
>>> +	rm -f headers.chk headers.lst lib*.map.tmp .*.tmp
>> Doesn't *.tmp cover lib*.map.tmp ?
> There is no "*.tmp" on this command line, but there is ".*.tmp".

Oh, of course.  I'm blind.  Sorry.

>
>> Also the subject still needs a FreeBSD->LLVM fix.
> Sounds good.
>
>> Both can be fixed on commit.
> If you only fix the subject, then that's fine by me.

Sure.  (Although I will throw this through CircleCI first...)

~Andrew

Re: [XEN PATCH v2] libs: Fix unstable libs build on FreeBSD, auto-generate version-script
Posted by Jan Beulich 1 year, 2 months ago
On 16.02.2023 17:50, Andrew Cooper wrote:
> On 16/02/2023 2:10 pm, Anthony PERARD wrote:
>> diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
>> index 0e4b5e0bd0..ffb6c9f064 100644
>> --- a/tools/libs/libs.mk
>> +++ b/tools/libs/libs.mk
>> @@ -120,7 +127,7 @@ TAGS:
>>  clean::
>>  	rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
>>  	rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
>> -	rm -f headers.chk headers.lst
>> +	rm -f headers.chk headers.lst lib*.map.tmp .*.tmp
> 
> Doesn't *.tmp cover lib*.map.tmp ?

It's .*.tmp, not *.tmp (but I agree the leading dot is easy to mistake).

Jan