public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* including redfish libs results in multiple definitions of symbols
@ 2022-05-25 16:23 M.T.
  2022-05-25 17:20 ` [edk2-devel] " Kilian Kegel
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: M.T. @ 2022-05-25 16:23 UTC (permalink / raw)
  To: devel

[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]

Hello

I'm working on a small UEFI shell app.
I was hoping to make use of the JsonLib found in the Redfish Package.

When I include the Redfish JsonLib and it's dependencies:
JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf

BaseSortLib has symbol clashes with SortLib resulting in the following:

/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
`PerformQuickSort':
(.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj
(symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
`PerformQuickSort':
(.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj
(symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
`PerformQuickSort':
(.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj
(symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
`PerformQuickSort':
(.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj
(symbol from plugin):(.text+0x0): first defined here

I need SortLib for UEFIShell dependencies, and I need BaseSortLib for
JsonLib.
Is there some way around this?  Or is Redfish meant to be standalone?

Thank you in advance
xp

[-- Attachment #2: Type: text/html, Size: 1790 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-25 16:23 including redfish libs results in multiple definitions of symbols M.T.
@ 2022-05-25 17:20 ` Kilian Kegel
       [not found] ` <16F268C9DA792DE0.12338@groups.io>
  2022-05-26  4:04 ` Andrew Fish
  2 siblings, 0 replies; 9+ messages in thread
From: Kilian Kegel @ 2022-05-25 17:20 UTC (permalink / raw)
  To: devel@edk2.groups.io, xzavierpower@gmail.com

[-- Attachment #1: Type: text/plain, Size: 3559 bytes --]

Hi xp,

your build failure is

  1.  the result of a “link-all” mechanism

or
       2. the result of a library construction flaw that is commonly used in EDK2.

or both

Let me explain the theory:


  1.  an .OBJ file is created by the compiler for each .C source code file

an .OBJ is considered as atomic, it can not be split into smaller pieces (except with newer compiler switches)

  1.  a “library“ .LIB is a collection of one or more of such .OBJ files
  2.  if an .OBJ is passed to linker, it is _always_ linked into the target.EFI

(the linker creates an link-error, like yours, if that particular symbol-name is already present in the target.EFI)

One definition rule: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  if an .LIB is passed to the linker instead, the linker searches the .LIB for a particular

symbol (e.g. function, data). The specific .OBJ module that holds that particular symbol, is

linked to the target.EFI.

(the linker creates an link-error, like yours, if that particular symbol-name is already present in the target.EFI)

One definition rule: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  to prevent such error each .OBJ of a library can hold only one single symbol, one function or one data.

Only in that case the linker is able to pickup each single symbol from the library and bind it into the target.EFI

without any conflict.


This is also explained here:
https://github.com/tianocore/edk2-staging/tree/CdePkg/blogs/2021-12-19#redfishcrtlib-conflicts-with-cdepkg-by-design

Best regards,
Kilian

________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of M.T. <xzavierpower@gmail.com>
Sent: Wednesday, May 25, 2022 6:23:02 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Subject: [edk2-devel] including redfish libs results in multiple definitions of symbols

Hello

I'm working on a small UEFI shell app.
I was hoping to make use of the JsonLib found in the Redfish Package.

When I include the Redfish JsonLib and it's dependencies:
JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf

BaseSortLib has symbol clashes with SortLib resulting in the following:

/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here

I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
Is there some way around this?  Or is Redfish meant to be standalone?

Thank you in advance
xp


[-- Attachment #2: Type: text/html, Size: 10165 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
       [not found] ` <16F268C9DA792DE0.12338@groups.io>
@ 2022-05-25 17:32   ` Kilian Kegel
  0 siblings, 0 replies; 9+ messages in thread
From: Kilian Kegel @ 2022-05-25 17:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, xzavierpower@gmail.com

[-- Attachment #1: Type: text/plain, Size: 4370 bytes --]

Correction:

  1.  if a .LIB is passed to the linker instead, the linker searches the .LIB for a particular

symbol (e.g. function, data). The specific .OBJ module that holds that particular symbol, is

linked to the target.EFI.

(the linker creates an link-error, like yours, if one or more symbol-name/s from that particular NON-one-definition-rule.OBJ is already present in the target.EFI)


________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Kilian Kegel <KILIAN_KEGEL@OUTLOOK.COM>
Sent: Wednesday, May 25, 2022 7:20:26 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>; xzavierpower@gmail.com <xzavierpower@gmail.com>
Subject: Re: [edk2-devel] including redfish libs results in multiple definitions of symbols


Hi xp,



your build failure is

  1.  the result of a “link-all” mechanism

or

       2. the result of a library construction flaw that is commonly used in EDK2.



or both



Let me explain the theory:



  1.  an .OBJ file is created by the compiler for each .C source code file

an .OBJ is considered as atomic, it can not be split into smaller pieces (except with newer compiler switches)

  1.  a “library“ .LIB is a collection of one or more of such .OBJ files
  2.  if an .OBJ is passed to linker, it is _always_ linked into the target.EFI

(the linker creates an link-error, like yours, if that particular symbol-name is already present in the target.EFI)

One definition rule: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  if an .LIB is passed to the linker instead, the linker searches the .LIB for a particular

symbol (e.g. function, data). The specific .OBJ module that holds that particular symbol, is

linked to the target.EFI.

(the linker creates an link-error, like yours, if that particular symbol-name is already present in the target.EFI)

One definition rule: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  to prevent such error each .OBJ of a library can hold only one single symbol, one function or one data.

Only in that case the linker is able to pickup each single symbol from the library and bind it into the target.EFI

without any conflict.



This is also explained here:

https://github.com/tianocore/edk2-staging/tree/CdePkg/blogs/2021-12-19#redfishcrtlib-conflicts-with-cdepkg-by-design



Best regards,

Kilian



________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of M.T. <xzavierpower@gmail.com>
Sent: Wednesday, May 25, 2022 6:23:02 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Subject: [edk2-devel] including redfish libs results in multiple definitions of symbols

Hello

I'm working on a small UEFI shell app.
I was hoping to make use of the JsonLib found in the Redfish Package.

When I include the Redfish JsonLib and it's dependencies:
JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf

BaseSortLib has symbol clashes with SortLib resulting in the following:

/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
(.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here

I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
Is there some way around this?  Or is Redfish meant to be standalone?

Thank you in advance
xp


[-- Attachment #2: Type: text/html, Size: 13487 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-25 16:23 including redfish libs results in multiple definitions of symbols M.T.
  2022-05-25 17:20 ` [edk2-devel] " Kilian Kegel
       [not found] ` <16F268C9DA792DE0.12338@groups.io>
@ 2022-05-26  4:04 ` Andrew Fish
  2022-05-26  4:07   ` Ethin Probst
  2 siblings, 1 reply; 9+ messages in thread
From: Andrew Fish @ 2022-05-26  4:04 UTC (permalink / raw)
  To: edk2-devel-groups-io, xzavierpower, Chang, Abner

[-- Attachment #1: Type: text/plain, Size: 4407 bytes --]



> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com> wrote:
> 
> Hello
> 
> I'm working on a small UEFI shell app.
> I was hoping to make use of the JsonLib found in the Redfish Package.
> 
> When I include the Redfish JsonLib and it's dependencies:
> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
> 
> BaseSortLib has symbol clashes with SortLib resulting in the following:
> 

It looks like BaseSortLib and and SortLib are the same library class so you should only have one. 

/Volumes/Case/edk2(master)>git grep --recurse-submodules SortLib  -- \*.inf | grep LIBRARY_CLASS 
MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS                  = SortLib
MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS                  = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER


/Volumes/Case/edk2(master)>git grep --recurse-submodules BaseSortLib  -- \*.inc
RedfishPkg/RedfishLibs.dsc.inc:16:  BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf

OK bingo bingo bingo….

The way the edk2 works is you have a library class that maps to the include file. This is the name in the INF file that resolves linking. You can have as many instances of the library class as you like. This is why the DSC files have the <library class name>|<path to INF file> syntax as you are letting the build pick which instance of the library to use. You can control this per driver/app if you want.

It looks to me like BaseSortLib is an alias for SortLib and that is a bit of hack. 

You could try making sure that BaseSortLib and SortLib point to the same library instance 

The other option would be to edit RedfishCrtLib.inf and make BaseSortLib SortLib

/Volumes/Case/edk2(master)>git grep --recurse-submodules BaseSortLib  -- \*.inf
MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME                      = BaseSortLib
MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE                = BaseSortLib.uni
MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:  BaseSortLib.c
RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:  BaseSortLib

I’m note sure why this fake BaseSortLib exists. Looks like we would need to ask Abner?

commit 6e9233f968735219b2038c5dd23a46be2c021807
Author: Abner Chang <abner.chang@hpe.com>
Date:   Fri Dec 4 12:30:05 2020 +0800

    RedfishPkg/RedfishCrtLib: Redfish C runtime library
    
    Redfish CRT library is currently used by edk2 JsonLib
    (open source jansson project) and edk2 RedfishLib
    (libredfish open source project). Redfish CrtLib library
    provides the necessary C runtime equivalent edk2 functions
    for open source projects.
    
    Signed-off-by: Abner Chang <abner.chang@hpe.com>
    
    Cc: Leif Lindholm <leif@nuviainc.com>
    Cc: Nickle Wang <nickle.wang@hpe.com>
    Cc: Peter O'Hanley <peter.ohanley@hpe.com>
    Reviewed-by: Nickle Wang <nickle.wang@hpe.com>
    Acked-by: Leif Lindholm <leif@nuviainc.com>
    Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>


Thanks,

Andrew Fish

> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
> (.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
> (.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
> (.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> 
> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
> Is there some way around this?  Or is Redfish meant to be standalone?
> 
> Thank you in advance
> xp
> 


[-- Attachment #2: Type: text/html, Size: 17659 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-26  4:04 ` Andrew Fish
@ 2022-05-26  4:07   ` Ethin Probst
  2022-05-26  4:11     ` Andrew Fish
  0 siblings, 1 reply; 9+ messages in thread
From: Ethin Probst @ 2022-05-26  4:07 UTC (permalink / raw)
  To: devel, afish, xzavierpower, Chang, Abner

aren't the Base*Libs there in case you want to override existing 
implementations or implement custom versions of them? I'm pretty sure 
that's the logic behind it -- its a hack of sorts to try to get OOP out 
of a purely procedural language. It works, but I don't think its 
necessarily ideal. But there really isn't much of an alternative. Then 
again, I might be wrong, too...

On 5/25/22 23:04, Andrew Fish via groups.io wrote:
> 
> 
>> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com 
>> <mailto:xzavierpower@gmail.com>> wrote:
>>
>> Hello
>>
>> I'm working on a small UEFI shell app.
>> I was hoping to make use of the JsonLib found in the Redfish Package.
>>
>> When I include the Redfish JsonLib and it's dependencies:
>> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
>> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
>> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
>> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
>>
>> BaseSortLib has symbol clashes with SortLib resulting in the following:
>>
> 
> It looks like BaseSortLib and and SortLib are the same library class so 
> you should only have one.
> 
> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules SortLib  -- 
> \*.inf | grep LIBRARY_CLASS
> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS      
>              = SortLib
> MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS      
>              = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER 
> DXE_RUNTIME_DRIVER DXE_DRIVER
> 
> 
> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  
> -- \*.inc
> RedfishPkg/RedfishLibs.dsc.inc:16:*BaseSortLib*|MdeModulePkg/Library/*BaseSortLib*/*BaseSortLib*.inf
> 
> OK bingo bingo bingo….
> 
> The way the edk2 works is you have a library class that maps to the 
> include file. This is the name in the INF file that resolves linking. 
> You can have as many instances of the library class as you like. This is 
> why the DSC files have the <library class name>|<path to INF file> 
> syntax as you are letting the build pick which instance of the library 
> to use. You can control this per driver/app if you want.
> 
> It looks to me like BaseSortLib is an alias for SortLib and that is a 
> bit of hack.
> 
> You could try making sure that BaseSortLib and SortLib point to the same 
> library instance
> 
> The other option would be to edit RedfishCrtLib.inf and make BaseSortLib 
> SortLib
> 
> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  
> -- \*.inf
> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME          
>              = *BaseSortLib*
> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE    
>              = *BaseSortLib*.uni
> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:*BaseSortLib*.c
> RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:*BaseSortLib*
> 
> I’m note sure why this fake BaseSortLib exists. Looks like we would need 
> to ask Abner?
> *
> *
> commit 6e9233f968735219b2038c5dd23a46be2c021807
> Author: Abner Chang <abner.chang@hpe.com <mailto:abner.chang@hpe.com>>
> Date:   Fri Dec 4 12:30:05 2020 +0800
> 
>      RedfishPkg/RedfishCrtLib: Redfish C runtime library
> 
> 
>      Redfish CRT library is currently used by edk2 JsonLib
>      (open source jansson project) and edk2 RedfishLib
>      (libredfish open source project). Redfish CrtLib library
>      provides the necessary C runtime equivalent edk2 functions
>      for open source projects.
> 
> 
>      Signed-off-by: Abner Chang <abner.chang@hpe.com 
> <mailto:abner.chang@hpe.com>>
> 
> 
>      Cc: Leif Lindholm <leif@nuviainc.com <mailto:leif@nuviainc.com>>
>      Cc: Nickle Wang <nickle.wang@hpe.com <mailto:nickle.wang@hpe.com>>
>      Cc: Peter O'Hanley <peter.ohanley@hpe.com 
> <mailto:peter.ohanley@hpe.com>>
>      Reviewed-by: Nickle Wang <nickle.wang@hpe.com 
> <mailto:nickle.wang@hpe.com>>
>      Acked-by: Leif Lindholm <leif@nuviainc.com <mailto:leif@nuviainc.com>>
>      Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com 
> <mailto:michael.d.kinney@intel.com>>
> 
> *
> *
> Thanks,
> 
> Andrew Fish
> 
>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
>> `PerformQuickSort':
>> (.text+0x0): multiple definition of `PerformQuickSort'; 
>> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
>> `PerformQuickSort':
>> (.text+0x0): multiple definition of `DevicePathCompare'; 
>> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
>> `PerformQuickSort':
>> (.text+0x0): multiple definition of `StringNoCaseCompare'; 
>> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
>> `PerformQuickSort':
>> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj 
>> (symbol from plugin):(.text+0x0): first defined here
>>
>> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for 
>> JsonLib.
>> Is there some way around this?  Or is Redfish meant to be standalone?
>>
>> Thank you in advance
>> xp
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-26  4:07   ` Ethin Probst
@ 2022-05-26  4:11     ` Andrew Fish
  2022-05-26 15:32       ` M.T.
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Fish @ 2022-05-26  4:11 UTC (permalink / raw)
  To: Ethin Probst; +Cc: devel, xzavierpower, Chang, Abner

In edk2 speak Base just means does not depend on any phase of boot, so basically standalone code. So you can pull a Base lib into SEC, PEI, DXE, SMM, etc. 

We never interned different Class Names for libs to map to the same library class when we designed the build system. 

One of the driving factors for the library classes was to not have to change your vendors driver INF file id you wanted to use a different instance of the DebugLib etc.

Thanks,

Andrew Fish

> On May 25, 2022, at 9:07 PM, Ethin Probst <harlydavidsen@gmail.com> wrote:
> 
> aren't the Base*Libs there in case you want to override existing implementations or implement custom versions of them? I'm pretty sure that's the logic behind it -- its a hack of sorts to try to get OOP out of a purely procedural language. It works, but I don't think its necessarily ideal. But there really isn't much of an alternative. Then again, I might be wrong, too...
> 
> On 5/25/22 23:04, Andrew Fish via groups.io wrote:
>>> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com <mailto:xzavierpower@gmail.com>> wrote:
>>> 
>>> Hello
>>> 
>>> I'm working on a small UEFI shell app.
>>> I was hoping to make use of the JsonLib found in the Redfish Package.
>>> 
>>> When I include the Redfish JsonLib and it's dependencies:
>>> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
>>> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
>>> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
>>> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
>>> 
>>> BaseSortLib has symbol clashes with SortLib resulting in the following:
>>> 
>> It looks like BaseSortLib and and SortLib are the same library class so you should only have one.
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules SortLib  -- \*.inf | grep LIBRARY_CLASS
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS                   = SortLib
>> MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS                   = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inc
>> RedfishPkg/RedfishLibs.dsc.inc:16:*BaseSortLib*|MdeModulePkg/Library/*BaseSortLib*/*BaseSortLib*.inf
>> OK bingo bingo bingo….
>> The way the edk2 works is you have a library class that maps to the include file. This is the name in the INF file that resolves linking. You can have as many instances of the library class as you like. This is why the DSC files have the <library class name>|<path to INF file> syntax as you are letting the build pick which instance of the library to use. You can control this per driver/app if you want.
>> It looks to me like BaseSortLib is an alias for SortLib and that is a bit of hack.
>> You could try making sure that BaseSortLib and SortLib point to the same library instance
>> The other option would be to edit RedfishCrtLib.inf and make BaseSortLib SortLib
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inf
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME                       = *BaseSortLib*
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE                 = *BaseSortLib*.uni
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:*BaseSortLib*.c
>> RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:*BaseSortLib*
>> I’m note sure why this fake BaseSortLib exists. Looks like we would need to ask Abner?
>> *
>> *
>> commit 6e9233f968735219b2038c5dd23a46be2c021807
>> Author: Abner Chang <abner.chang@hpe.com <mailto:abner.chang@hpe.com>>
>> Date:   Fri Dec 4 12:30:05 2020 +0800
>>     RedfishPkg/RedfishCrtLib: Redfish C runtime library
>>     Redfish CRT library is currently used by edk2 JsonLib
>>     (open source jansson project) and edk2 RedfishLib
>>     (libredfish open source project). Redfish CrtLib library
>>     provides the necessary C runtime equivalent edk2 functions
>>     for open source projects.
>>     Signed-off-by: Abner Chang <abner.chang@hpe.com <mailto:abner.chang@hpe.com>>
>>     Cc: Leif Lindholm <leif@nuviainc.com <mailto:leif@nuviainc.com>>
>>     Cc: Nickle Wang <nickle.wang@hpe.com <mailto:nickle.wang@hpe.com>>
>>     Cc: Peter O'Hanley <peter.ohanley@hpe.com <mailto:peter.ohanley@hpe.com>>
>>     Reviewed-by: Nickle Wang <nickle.wang@hpe.com <mailto:nickle.wang@hpe.com>>
>>     Acked-by: Leif Lindholm <leif@nuviainc.com <mailto:leif@nuviainc.com>>
>>     Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com>>
>> *
>> *
>> Thanks,
>> Andrew Fish
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> 
>>> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
>>> Is there some way around this?  Or is Redfish meant to be standalone?
>>> 
>>> Thank you in advance
>>> xp
>> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-26  4:11     ` Andrew Fish
@ 2022-05-26 15:32       ` M.T.
  2022-05-26 17:06         ` Kilian Kegel
  0 siblings, 1 reply; 9+ messages in thread
From: M.T. @ 2022-05-26 15:32 UTC (permalink / raw)
  To: devel, afish; +Cc: Ethin Probst, Chang, Abner

[-- Attachment #1: Type: text/plain, Size: 6621 bytes --]

Thank you for the feedback

Kilian, your suggestion makes sense unfortunately I am working with GNU
toolchain so I don't think I will be able to take advantage of it just yet.

Andrew, I have not thought about renaming the libraries, I will give this a
try to see if I can get rid of the duplicate symbols, it seems like it
should work, thank you very much for that suggestion.

Thank you
xp

On Thu, May 26, 2022 at 12:11 AM Andrew Fish via groups.io <afish=
apple.com@groups.io> wrote:

> In edk2 speak Base just means does not depend on any phase of boot, so
> basically standalone code. So you can pull a Base lib into SEC, PEI, DXE,
> SMM, etc.
>
> We never interned different Class Names for libs to map to the same
> library class when we designed the build system.
>
> One of the driving factors for the library classes was to not have to
> change your vendors driver INF file id you wanted to use a different
> instance of the DebugLib etc.
>
> Thanks,
>
> Andrew Fish
>
> > On May 25, 2022, at 9:07 PM, Ethin Probst <harlydavidsen@gmail.com>
> wrote:
> >
> > aren't the Base*Libs there in case you want to override existing
> implementations or implement custom versions of them? I'm pretty sure
> that's the logic behind it -- its a hack of sorts to try to get OOP out of
> a purely procedural language. It works, but I don't think its necessarily
> ideal. But there really isn't much of an alternative. Then again, I might
> be wrong, too...
> >
> > On 5/25/22 23:04, Andrew Fish via groups.io wrote:
> >>> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com <mailto:
> xzavierpower@gmail.com>> wrote:
> >>>
> >>> Hello
> >>>
> >>> I'm working on a small UEFI shell app.
> >>> I was hoping to make use of the JsonLib found in the Redfish Package.
> >>>
> >>> When I include the Redfish JsonLib and it's dependencies:
> >>> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
> >>> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
> >>> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> >>> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
> >>>
> >>> BaseSortLib has symbol clashes with SortLib resulting in the following:
> >>>
> >> It looks like BaseSortLib and and SortLib are the same library class so
> you should only have one.
> >> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules SortLib  --
> \*.inf | grep LIBRARY_CLASS
> >> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS
>                = SortLib
> >> MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS
>                = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER
> DXE_RUNTIME_DRIVER DXE_DRIVER
> >> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib
> -- \*.inc
> >>
> RedfishPkg/RedfishLibs.dsc.inc:16:*BaseSortLib*|MdeModulePkg/Library/*BaseSortLib*/*BaseSortLib*.inf
> >> OK bingo bingo bingo….
> >> The way the edk2 works is you have a library class that maps to the
> include file. This is the name in the INF file that resolves linking. You
> can have as many instances of the library class as you like. This is why
> the DSC files have the <library class name>|<path to INF file> syntax as
> you are letting the build pick which instance of the library to use. You
> can control this per driver/app if you want.
> >> It looks to me like BaseSortLib is an alias for SortLib and that is a
> bit of hack.
> >> You could try making sure that BaseSortLib and SortLib point to the
> same library instance
> >> The other option would be to edit RedfishCrtLib.inf and make
> BaseSortLib SortLib
> >> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib
> -- \*.inf
> >> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME
>                = *BaseSortLib*
> >> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE
>                = *BaseSortLib*.uni
> >> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:*BaseSortLib*.c
> >>
> RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:*BaseSortLib*
> >> I’m note sure why this fake BaseSortLib exists. Looks like we would
> need to ask Abner?
> >> *
> >> *
> >> commit 6e9233f968735219b2038c5dd23a46be2c021807
> >> Author: Abner Chang <abner.chang@hpe.com <mailto:abner.chang@hpe.com>>
> >> Date:   Fri Dec 4 12:30:05 2020 +0800
> >>     RedfishPkg/RedfishCrtLib: Redfish C runtime library
> >>     Redfish CRT library is currently used by edk2 JsonLib
> >>     (open source jansson project) and edk2 RedfishLib
> >>     (libredfish open source project). Redfish CrtLib library
> >>     provides the necessary C runtime equivalent edk2 functions
> >>     for open source projects.
> >>     Signed-off-by: Abner Chang <abner.chang@hpe.com <mailto:
> abner.chang@hpe.com>>
> >>     Cc: Leif Lindholm <leif@nuviainc.com <mailto:leif@nuviainc.com>>
> >>     Cc: Nickle Wang <nickle.wang@hpe.com <mailto:nickle.wang@hpe.com>>
> >>     Cc: Peter O'Hanley <peter.ohanley@hpe.com <mailto:
> peter.ohanley@hpe.com>>
> >>     Reviewed-by: Nickle Wang <nickle.wang@hpe.com <mailto:
> nickle.wang@hpe.com>>
> >>     Acked-by: Leif Lindholm <leif@nuviainc.com <mailto:
> leif@nuviainc.com>>
> >>     Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com <mailto:
> michael.d.kinney@intel.com>>
> >> *
> >> *
> >> Thanks,
> >> Andrew Fish
> >>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
> `PerformQuickSort':
> >>> (.text+0x0): multiple definition of `PerformQuickSort';
> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> >>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
> `PerformQuickSort':
> >>> (.text+0x0): multiple definition of `DevicePathCompare';
> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> >>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
> `PerformQuickSort':
> >>> (.text+0x0): multiple definition of `StringNoCaseCompare';
> BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
> >>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function
> `PerformQuickSort':
> >>> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj
> (symbol from plugin):(.text+0x0): first defined here
> >>>
> >>> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for
> JsonLib.
> >>> Is there some way around this?  Or is Redfish meant to be standalone?
> >>>
> >>> Thank you in advance
> >>> xp
> >>
>
>
>
> 
>
>
>

[-- Attachment #2: Type: text/html, Size: 9050 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-26 15:32       ` M.T.
@ 2022-05-26 17:06         ` Kilian Kegel
  2022-05-27  4:59           ` Abner Chang
  0 siblings, 1 reply; 9+ messages in thread
From: Kilian Kegel @ 2022-05-26 17:06 UTC (permalink / raw)
  To: devel@edk2.groups.io, xzavierpower@gmail.com, afish@apple.com
  Cc: Ethin Probst, Chang, Abner


[-- Attachment #1.1: Type: text/plain, Size: 8031 bytes --]

Hi xp,

Sorry: I didn’t suggest, I just explained the root cause for such trouble.
That is true for all tool chains.

But, comparing the two library files from the sourcecode MdeModulePkg
tells me, that the QuickSortWorker() and  PerformQuickSort() functions are identical.

Why do we have two different libraries in the same package MdeModulePkg that provides
the same functions?

And why are both pulled into the built?
(because of an indirect dependency. I also believe that a renaming of all BaseSortLib to UefiSortLib in the .INF files,
or to exclude BaseSortLib, could be a workaround for your particular problem – but it doesn’t solve the root cause)

Best regards,
Kilian

[cid:image001.png@01D87133.B8B1CB00]

From: M.T.<mailto:xzavierpower@gmail.com>
Sent: Thursday, May 26, 2022 05:32 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; afish@apple.com<mailto:afish@apple.com>
Cc: Ethin Probst<mailto:harlydavidsen@gmail.com>; Chang, Abner<mailto:abner.chang@hpe.com>
Subject: Re: [edk2-devel] including redfish libs results in multiple definitions of symbols

Thank you for the feedback

Kilian, your suggestion makes sense unfortunately I am working with GNU toolchain so I don't think I will be able to take advantage of it just yet.

Andrew, I have not thought about renaming the libraries, I will give this a try to see if I can get rid of the duplicate symbols, it seems like it should work, thank you very much for that suggestion.

Thank you
xp

On Thu, May 26, 2022 at 12:11 AM Andrew Fish via groups.io<http://groups.io> <afish=apple.com@groups.io<mailto:apple.com@groups.io>> wrote:
In edk2 speak Base just means does not depend on any phase of boot, so basically standalone code. So you can pull a Base lib into SEC, PEI, DXE, SMM, etc.

We never interned different Class Names for libs to map to the same library class when we designed the build system.

One of the driving factors for the library classes was to not have to change your vendors driver INF file id you wanted to use a different instance of the DebugLib etc.

Thanks,

Andrew Fish

> On May 25, 2022, at 9:07 PM, Ethin Probst <harlydavidsen@gmail.com<mailto:harlydavidsen@gmail.com>> wrote:
>
> aren't the Base*Libs there in case you want to override existing implementations or implement custom versions of them? I'm pretty sure that's the logic behind it -- its a hack of sorts to try to get OOP out of a purely procedural language. It works, but I don't think its necessarily ideal. But there really isn't much of an alternative. Then again, I might be wrong, too...
>
> On 5/25/22 23:04, Andrew Fish via groups.io<http://groups.io> wrote:
>>> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com<mailto:xzavierpower@gmail.com> <mailto:xzavierpower@gmail.com<mailto:xzavierpower@gmail.com>>> wrote:
>>>
>>> Hello
>>>
>>> I'm working on a small UEFI shell app.
>>> I was hoping to make use of the JsonLib found in the Redfish Package.
>>>
>>> When I include the Redfish JsonLib and it's dependencies:
>>> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
>>> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
>>> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
>>> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
>>>
>>> BaseSortLib has symbol clashes with SortLib resulting in the following:
>>>
>> It looks like BaseSortLib and and SortLib are the same library class so you should only have one.
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules SortLib  -- \*.inf | grep LIBRARY_CLASS
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS                   = SortLib
>> MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS                   = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inc
>> RedfishPkg/RedfishLibs.dsc.inc:16:*BaseSortLib*|MdeModulePkg/Library/*BaseSortLib*/*BaseSortLib*.inf
>> OK bingo bingo bingo….
>> The way the edk2 works is you have a library class that maps to the include file. This is the name in the INF file that resolves linking. You can have as many instances of the library class as you like. This is why the DSC files have the <library class name>|<path to INF file> syntax as you are letting the build pick which instance of the library to use. You can control this per driver/app if you want.
>> It looks to me like BaseSortLib is an alias for SortLib and that is a bit of hack.
>> You could try making sure that BaseSortLib and SortLib point to the same library instance
>> The other option would be to edit RedfishCrtLib.inf and make BaseSortLib SortLib
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inf
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME                       = *BaseSortLib*
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE                 = *BaseSortLib*.uni
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:*BaseSortLib*.c
>> RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:*BaseSortLib*
>> I’m note sure why this fake BaseSortLib exists. Looks like we would need to ask Abner?
>> *
>> *
>> commit 6e9233f968735219b2038c5dd23a46be2c021807
>> Author: Abner Chang <abner.chang@hpe.com<mailto:abner.chang@hpe.com> <mailto:abner.chang@hpe.com<mailto:abner.chang@hpe.com>>>
>> Date:   Fri Dec 4 12:30:05 2020 +0800
>>     RedfishPkg/RedfishCrtLib: Redfish C runtime library
>>     Redfish CRT library is currently used by edk2 JsonLib
>>     (open source jansson project) and edk2 RedfishLib
>>     (libredfish open source project). Redfish CrtLib library
>>     provides the necessary C runtime equivalent edk2 functions
>>     for open source projects.
>>     Signed-off-by: Abner Chang <abner.chang@hpe.com<mailto:abner.chang@hpe.com> <mailto:abner.chang@hpe.com<mailto:abner.chang@hpe.com>>>
>>     Cc: Leif Lindholm <leif@nuviainc.com<mailto:leif@nuviainc.com> <mailto:leif@nuviainc.com<mailto:leif@nuviainc.com>>>
>>     Cc: Nickle Wang <nickle.wang@hpe.com<mailto:nickle.wang@hpe.com> <mailto:nickle.wang@hpe.com<mailto:nickle.wang@hpe.com>>>
>>     Cc: Peter O'Hanley <peter.ohanley@hpe.com<mailto:peter.ohanley@hpe.com> <mailto:peter.ohanley@hpe.com<mailto:peter.ohanley@hpe.com>>>
>>     Reviewed-by: Nickle Wang <nickle.wang@hpe.com<mailto:nickle.wang@hpe.com> <mailto:nickle.wang@hpe.com<mailto:nickle.wang@hpe.com>>>
>>     Acked-by: Leif Lindholm <leif@nuviainc.com<mailto:leif@nuviainc.com> <mailto:leif@nuviainc.com<mailto:leif@nuviainc.com>>>
>>     Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com> <mailto:michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>>
>> *
>> *
>> Thanks,
>> Andrew Fish
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>>
>>> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
>>> Is there some way around this?  Or is Redfish meant to be standalone?
>>>
>>> Thank you in advance
>>> xp
>>








[-- Attachment #1.2: Type: text/html, Size: 13464 bytes --]

[-- Attachment #2: 9B4BE2FD876042309284F89C528452ED.png --]
[-- Type: image/png, Size: 546136 bytes --]

[-- Attachment #3: 37F3232F26ED4C5E8CDF219ABDC97F26.png --]
[-- Type: image/png, Size: 132 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [edk2-devel] including redfish libs results in multiple definitions of symbols
  2022-05-26 17:06         ` Kilian Kegel
@ 2022-05-27  4:59           ` Abner Chang
  0 siblings, 0 replies; 9+ messages in thread
From: Abner Chang @ 2022-05-27  4:59 UTC (permalink / raw)
  To: Kilian Kegel, devel@edk2.groups.io, xzavierpower@gmail.com,
	afish@apple.com
  Cc: Ethin Probst


[-- Attachment #1.1: Type: text/plain, Size: 8800 bytes --]

As I can remember we did not create BaseSortlib. We use PerformQuickSort for qsort in CRT lib from BaseSortLib, and BaseSortLib seems lighter than the UefiSortlib. I don't know the history the reason having two SortLib instances under MdeModulepkg.
Maybe we should consolidate those into one.

Xp,
Did you try to use BaseSortLib for ShellPkg? Any unresolved external reference happens if use BaseSortLib?
Abner

From: Kilian Kegel <kilian_kegel@outlook.com>
Sent: Friday, May 27, 2022 1:07 AM
To: devel@edk2.groups.io; xzavierpower@gmail.com; afish@apple.com
Cc: Ethin Probst <harlydavidsen@gmail.com>; Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>
Subject: RE: [edk2-devel] including redfish libs results in multiple definitions of symbols

Hi xp,

Sorry: I didn't suggest, I just explained the root cause for such trouble.
That is true for all tool chains.

But, comparing the two library files from the sourcecode MdeModulePkg
tells me, that the QuickSortWorker() and  PerformQuickSort() functions are identical.

Why do we have two different libraries in the same package MdeModulePkg that provides
the same functions?

And why are both pulled into the built?
(because of an indirect dependency. I also believe that a renaming of all BaseSortLib to UefiSortLib in the .INF files,
or to exclude BaseSortLib, could be a workaround for your particular problem - but it doesn't solve the root cause)

Best regards,
Kilian

[cid:image001.png@01D871C7.DEA426C0]

From: M.T.<mailto:xzavierpower@gmail.com>
Sent: Thursday, May 26, 2022 05:32 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; afish@apple.com<mailto:afish@apple.com>
Cc: Ethin Probst<mailto:harlydavidsen@gmail.com>; Chang, Abner<mailto:abner.chang@hpe.com>
Subject: Re: [edk2-devel] including redfish libs results in multiple definitions of symbols

Thank you for the feedback

Kilian, your suggestion makes sense unfortunately I am working with GNU toolchain so I don't think I will be able to take advantage of it just yet.

Andrew, I have not thought about renaming the libraries, I will give this a try to see if I can get rid of the duplicate symbols, it seems like it should work, thank you very much for that suggestion.

Thank you
xp

On Thu, May 26, 2022 at 12:11 AM Andrew Fish via groups.io<http://groups.io> <afish=apple.com@groups.io<mailto:apple.com@groups.io>> wrote:
In edk2 speak Base just means does not depend on any phase of boot, so basically standalone code. So you can pull a Base lib into SEC, PEI, DXE, SMM, etc.

We never interned different Class Names for libs to map to the same library class when we designed the build system.

One of the driving factors for the library classes was to not have to change your vendors driver INF file id you wanted to use a different instance of the DebugLib etc.

Thanks,

Andrew Fish

> On May 25, 2022, at 9:07 PM, Ethin Probst <harlydavidsen@gmail.com<mailto:harlydavidsen@gmail.com>> wrote:
>
> aren't the Base*Libs there in case you want to override existing implementations or implement custom versions of them? I'm pretty sure that's the logic behind it -- its a hack of sorts to try to get OOP out of a purely procedural language. It works, but I don't think its necessarily ideal. But there really isn't much of an alternative. Then again, I might be wrong, too...
>
> On 5/25/22 23:04, Andrew Fish via groups.io<http://groups.io> wrote:
>>> On May 25, 2022, at 9:23 AM, M.T. <xzavierpower@gmail.com<mailto:xzavierpower@gmail.com> <mailto:xzavierpower@gmail.com<mailto:xzavierpower@gmail.com>>> wrote:
>>>
>>> Hello
>>>
>>> I'm working on a small UEFI shell app.
>>> I was hoping to make use of the JsonLib found in the Redfish Package.
>>>
>>> When I include the Redfish JsonLib and it's dependencies:
>>> JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
>>> Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
>>> RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
>>> BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
>>>
>>> BaseSortLib has symbol clashes with SortLib resulting in the following:
>>>
>> It looks like BaseSortLib and and SortLib are the same library class so you should only have one.
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules SortLib  -- \*.inf | grep LIBRARY_CLASS
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:18:  LIBRARY_CLASS                   = SortLib
>> MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf:18:  LIBRARY_CLASS                   = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inc
>> RedfishPkg/RedfishLibs.dsc.inc:16:*BaseSortLib*|MdeModulePkg/Library/*BaseSortLib*/*BaseSortLib*.inf
>> OK bingo bingo bingo....
>> The way the edk2 works is you have a library class that maps to the include file. This is the name in the INF file that resolves linking. You can have as many instances of the library class as you like. This is why the DSC files have the <library class name>|<path to INF file> syntax as you are letting the build pick which instance of the library to use. You can control this per driver/app if you want.
>> It looks to me like BaseSortLib is an alias for SortLib and that is a bit of hack.
>> You could try making sure that BaseSortLib and SortLib point to the same library instance
>> The other option would be to edit RedfishCrtLib.inf and make BaseSortLib SortLib
>> /Volumes/Case/edk2(master)*>*git grep --recurse-submodules BaseSortLib  -- \*.inf
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:13:  BASE_NAME                       = *BaseSortLib*
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:14:  MODULE_UNI_FILE                 = *BaseSortLib*.uni
>> MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf:25:*BaseSortLib*.c
>> RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf:28:*BaseSortLib*
>> I'm note sure why this fake BaseSortLib exists. Looks like we would need to ask Abner?
>> *
>> *
>> commit 6e9233f968735219b2038c5dd23a46be2c021807
>> Author: Abner Chang <abner.chang@hpe.com<mailto:abner.chang@hpe.com> <mailto:abner.chang@hpe.com<mailto:abner.chang@hpe.com>>>
>> Date:   Fri Dec 4 12:30:05 2020 +0800
>>     RedfishPkg/RedfishCrtLib: Redfish C runtime library
>>     Redfish CRT library is currently used by edk2 JsonLib
>>     (open source jansson project) and edk2 RedfishLib
>>     (libredfish open source project). Redfish CrtLib library
>>     provides the necessary C runtime equivalent edk2 functions
>>     for open source projects.
>>     Signed-off-by: Abner Chang <abner.chang@hpe.com<mailto:abner.chang@hpe.com> <mailto:abner.chang@hpe.com<mailto:abner.chang@hpe.com>>>
>>     Cc: Leif Lindholm <leif@nuviainc.com<mailto:leif@nuviainc.com> <mailto:leif@nuviainc.com<mailto:leif@nuviainc.com>>>
>>     Cc: Nickle Wang <nickle.wang@hpe.com<mailto:nickle.wang@hpe.com> <mailto:nickle.wang@hpe.com<mailto:nickle.wang@hpe.com>>>
>>     Cc: Peter O'Hanley <peter.ohanley@hpe.com<mailto:peter.ohanley@hpe.com> <mailto:peter.ohanley@hpe.com<mailto:peter.ohanley@hpe.com>>>
>>     Reviewed-by: Nickle Wang <nickle.wang@hpe.com<mailto:nickle.wang@hpe.com> <mailto:nickle.wang@hpe.com<mailto:nickle.wang@hpe.com>>>
>>     Acked-by: Leif Lindholm <leif@nuviainc.com<mailto:leif@nuviainc.com> <mailto:leif@nuviainc.com<mailto:leif@nuviainc.com>>>
>>     Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com> <mailto:michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>>
>> *
>> *
>> Thanks,
>> Andrew Fish
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>> /usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function `PerformQuickSort':
>>> (.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol from plugin):(.text+0x0): first defined here
>>>
>>> I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
>>> Is there some way around this?  Or is Redfish meant to be standalone?
>>>
>>> Thank you in advance
>>> xp
>>







[-- Attachment #1.2: Type: text/html, Size: 15383 bytes --]

[-- Attachment #2: image001.png --]
[-- Type: image/png, Size: 546136 bytes --]

[-- Attachment #3: image002.png --]
[-- Type: image/png, Size: 132 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-27  5:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-25 16:23 including redfish libs results in multiple definitions of symbols M.T.
2022-05-25 17:20 ` [edk2-devel] " Kilian Kegel
     [not found] ` <16F268C9DA792DE0.12338@groups.io>
2022-05-25 17:32   ` Kilian Kegel
2022-05-26  4:04 ` Andrew Fish
2022-05-26  4:07   ` Ethin Probst
2022-05-26  4:11     ` Andrew Fish
2022-05-26 15:32       ` M.T.
2022-05-26 17:06         ` Kilian Kegel
2022-05-27  4:59           ` Abner Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox