All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* What is the correct way to add linker dependency to QEMU build system?
@ 2024-02-29 16:09 Paz Offer
  2024-02-29 17:02 ` Alex Bennée
  2024-02-29 17:34 ` Peter Maydell
  0 siblings, 2 replies; 7+ messages in thread
From: Paz Offer @ 2024-02-29 16:09 UTC (permalink / raw
  To: qemu-devel@nongnu.org

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

Hi,

I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary dependencies list.
However, in QEMU I understand that these configurations are done in the './configure' file?

What would be the correct way to do this?

Thanks,
Paz




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

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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-02-29 16:09 What is the correct way to add linker dependency to QEMU build system? Paz Offer
@ 2024-02-29 17:02 ` Alex Bennée
  2024-02-29 21:22   ` Paolo Bonzini
  2024-02-29 17:34 ` Peter Maydell
  1 sibling, 1 reply; 7+ messages in thread
From: Alex Bennée @ 2024-02-29 17:02 UTC (permalink / raw
  To: Paz Offer; +Cc: qemu-devel@nongnu.org, Paolo Bonzini

Paz Offer <poffer@nvidia.com> writes:

> Hi,
>
> I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
> Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary
> dependencies list.
> However, in QEMU I understand that these configurations are done in
> the './configure' file?

No I'm pretty sure all the library finding is done in meson now:

  21:elf = cc.find_library('elf', required: true)                                 
  22:procstat = cc.find_library('procstat', required: true)                       
  23:kvm = cc.find_library('kvm', required: true)                                 
  663:libm = cc.find_library('m', required: false)                                
  665:util = cc.find_library('util', required: false)                             
  679:  pathcch = cc.find_library('pathcch')                                      
  680:  socket = cc.find_library('ws2_32')                                        
  681:  winmm = cc.find_library('winmm')                                          
  693:  socket = [cc.find_library('socket'),                                      
  694:            cc.find_library('nsl'),                                         
  695:            cc.find_library('resolv')]                                      
  697:  socket = [cc.find_library('posix_error_mapper'),                          
  698:            cc.find_library('network'),                                     
  699:            cc.find_library('bsd')]                                         
  735:  nvmm = cc.find_library('nvmm', required: get_option('nvmm'))              
  827:          xen_deps += { l: cc.find_library(l, required: false) }            
  986:  libaio = cc.find_library('aio', has_headers: ['libaio.h'],                
  1029:    libattr = cc.find_library('attr', has_headers: ['attr/xattr.h'],       
  1075:  libcap_ng = cc.find_library('cap-ng', has_headers: ['cap-ng.h'],         
  1122:  vde = cc.find_library('vdeplug', has_headers: ['libvdeplug.h'],          
  1187:rt = cc.find_library('rt', required: false)                                
  1254:  libmpathpersist = cc.find_library('mpathpersist',                        
  1259:      mpathlibs += cc.find_library('devmapper',                            
  1262:    mpathlibs += cc.find_library('multipath',                              
  1332:        libcurses = cc.find_library(curses_libname,                        
  1382:  brlapi = cc.find_library('brlapi', has_headers: ['brlapi.h'],            
  1425:  librados = cc.find_library('rados', required: get_option('rbd'))         
  1426:  librbd = cc.find_library('rbd', has_headers: ['rbd/librbd.h'],           
  1519:  libbzip2 = cc.find_library('bz2', has_headers: ['bzlib.h'],              
  1535:  liblzfse = cc.find_library('lzfse', has_headers: ['lzfse.h'],            
  1554:    oss = cc.find_library('ossaudio', required: get_option('oss'))         
  1660:         cc.find_library('gpg-error', required: true)],                    
  1774:  sasl = cc.find_library('sasl2', has_headers: ['sasl/sasl.h'],            
  1784:  pam = cc.find_library('pam', has_headers: ['security/pam_appl.h'],       
  1808:  snappy = cc.find_library('snappy', has_headers: ['snappy-c.h'],          
  1824:  lzo = cc.find_library('lzo2', has_headers: ['lzo/lzo1x.h'],              
  1840:  numa = cc.find_library('numa', has_headers: ['numa.h'],                  
  1857:  libumad = cc.find_library('ibumad', required: get_option('rdma'))        
  1858:  rdma_libs = [cc.find_library('rdmacm', has_headers: ['rdma/rdma_cma.h'], 
  1860:               cc.find_library('ibverbs', required: get_option('rdma')),   
  1933:  malloc = cc.find_library(get_option('malloc'), required: true)           
  2420:  inotify = cc.find_library('inotify')                                     
  3164:    fdt = cc.find_library('fdt', required: fdt_opt == 'system')            
  18:    cc.find_library('ole32'),                                                
  19:    cc.find_library('oleaut32'),                                             
  20:    cc.find_library('shlwapi'),                                              
  21:    cc.find_library('uuid'),                                                 
  22:    cc.find_library('intl')                                                  


>
> What would be the correct way to do this?
>
> Thanks,
> Paz

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Date: Thu, 29 Feb 2024 17:02:44 +0000


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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-02-29 16:09 What is the correct way to add linker dependency to QEMU build system? Paz Offer
  2024-02-29 17:02 ` Alex Bennée
@ 2024-02-29 17:34 ` Peter Maydell
  2024-02-29 19:00   ` Paz Offer
  2024-03-06  6:05   ` Paz Offer
  1 sibling, 2 replies; 7+ messages in thread
From: Peter Maydell @ 2024-02-29 17:34 UTC (permalink / raw
  To: Paz Offer; +Cc: qemu-devel@nongnu.org

On Thu, 29 Feb 2024 at 16:10, Paz Offer <poffer@nvidia.com> wrote:
> I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
> Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary dependencies list.
> However, in QEMU I understand that these configurations are done in the './configure' file?
>
> What would be the correct way to do this?

If you can do the job using the glib g_module_open()/
g_module_symbol() functions (which is how QEMU itself does
loading of plugin and module DLLs, and which on Unix hosts
are pretty much wrappers around dlopen/dlsym) then you
don't need to link against libdl at all.

If this is for something you're planning to upstream
then it might be worth talking at a higher level about
what you're aiming to do. (If it's for something downstream
that you don't plan to ever upstream then you can do
whatever's easiest for you, of course.)

-- PMM


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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-02-29 17:34 ` Peter Maydell
@ 2024-02-29 19:00   ` Paz Offer
  2024-03-06  6:05   ` Paz Offer
  1 sibling, 0 replies; 7+ messages in thread
From: Paz Offer @ 2024-02-29 19:00 UTC (permalink / raw
  To: Peter Maydell; +Cc: qemu-devel@nongnu.org

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

Thanks a lot Peter,
This is working.
Paz
________________________________
From: Peter Maydell <peter.maydell@linaro.org>
Sent: Thursday, February 29, 2024 7:34 PM
To: Paz Offer <poffer@nvidia.com>
Cc: qemu-devel@nongnu.org <qemu-devel@nongnu.org>
Subject: Re: What is the correct way to add linker dependency to QEMU build system?

External email: Use caution opening links or attachments


On Thu, 29 Feb 2024 at 16:10, Paz Offer <poffer@nvidia.com> wrote:
> I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
> Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary dependencies list.
> However, in QEMU I understand that these configurations are done in the './configure' file?
>
> What would be the correct way to do this?

If you can do the job using the glib g_module_open()/
g_module_symbol() functions (which is how QEMU itself does
loading of plugin and module DLLs, and which on Unix hosts
are pretty much wrappers around dlopen/dlsym) then you
don't need to link against libdl at all.

If this is for something you're planning to upstream
then it might be worth talking at a higher level about
what you're aiming to do. (If it's for something downstream
that you don't plan to ever upstream then you can do
whatever's easiest for you, of course.)

-- PMM

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

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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-02-29 17:02 ` Alex Bennée
@ 2024-02-29 21:22   ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2024-02-29 21:22 UTC (permalink / raw
  To: Alex Bennée; +Cc: Paz Offer, qemu-devel@nongnu.org

On Thu, Feb 29, 2024 at 6:02 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Paz Offer <poffer@nvidia.com> writes:
>
> > Hi,
> >
> > I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
> > Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary
> > dependencies list.
> > However, in QEMU I understand that these configurations are done in
> > the './configure' file?
>
> No I'm pretty sure all the library finding is done in meson now:

Yes, indeed. The documentation lists the tasks of the configure script:

- detect the host architecture

- list the targets for which to build emulators; the list of targets
also affects which firmware binaries and tests to build

- find the compilers (native and cross) used to build executables,
firmware and tests.  The results are written as either Makefile
fragments (``config-host.mak``) or a Meson machine file
(``config-meson.cross``)

- create a virtual environment in which all Python code runs during
the build, and possibly install packages into it from PyPI

- invoke Meson in the virtual environment, to perform the actual
configuration step for the emulator build

Anything related to 1) building executables and documentation 2)
installing is done in meson.

Generally, non-Meson parts of the bulid system are limited to stuff
that has to be cross compiled. The exception is
contrib/plugins/Makefile (which I mention because you might be
interested in it as well), but that's just for documentation purposes,
so that it can be lifted out of the QEMU tree and used to build custom
plugins.

Paolo



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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-02-29 17:34 ` Peter Maydell
  2024-02-29 19:00   ` Paz Offer
@ 2024-03-06  6:05   ` Paz Offer
  2024-03-06  9:28     ` Alex Bennée
  1 sibling, 1 reply; 7+ messages in thread
From: Paz Offer @ 2024-03-06  6:05 UTC (permalink / raw
  To: Peter Maydell; +Cc: qemu-devel@nongnu.org

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

...after some testing...
[Trying to add 'libdl' to be linked with QEMU]

I did try to use 'g_module_open/close/symbol', but what I noticed is that 'g_module_close' did not really unload my library.
So if I would do:

  1.  g_module_open(my-lib)
  2.  Load symbols, use my library...
  3.  g_module_close(my-lib)
  4.  Make modifications to my library and reload it:
  5.  g_module_open(my-lib)

Then the library was not really reloaded, and the old instance would still be used.

This did not happen when I used dlopen/dlclose.
Do we have a way to force 'g_module_close' to unload the library?

Thanks, Paz


________________________________
From: Peter Maydell <peter.maydell@linaro.org>
Sent: Thursday, February 29, 2024 7:34 PM
To: Paz Offer <poffer@nvidia.com>
Cc: qemu-devel@nongnu.org <qemu-devel@nongnu.org>
Subject: Re: What is the correct way to add linker dependency to QEMU build system?

External email: Use caution opening links or attachments


On Thu, 29 Feb 2024 at 16:10, Paz Offer <poffer@nvidia.com> wrote:
> I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
> Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary dependencies list.
> However, in QEMU I understand that these configurations are done in the './configure' file?
>
> What would be the correct way to do this?

If you can do the job using the glib g_module_open()/
g_module_symbol() functions (which is how QEMU itself does
loading of plugin and module DLLs, and which on Unix hosts
are pretty much wrappers around dlopen/dlsym) then you
don't need to link against libdl at all.

If this is for something you're planning to upstream
then it might be worth talking at a higher level about
what you're aiming to do. (If it's for something downstream
that you don't plan to ever upstream then you can do
whatever's easiest for you, of course.)

-- PMM

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

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

* Re: What is the correct way to add linker dependency to QEMU build system?
  2024-03-06  6:05   ` Paz Offer
@ 2024-03-06  9:28     ` Alex Bennée
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Bennée @ 2024-03-06  9:28 UTC (permalink / raw
  To: Paz Offer; +Cc: Peter Maydell, qemu-devel@nongnu.org

Paz Offer <poffer@nvidia.com> writes:

> ...after some testing...
> [Trying to add 'libdl' to be linked with QEMU]
>
> I did try to use 'g_module_open/close/symbol', but what I noticed is that 'g_module_close' did not really unload my library.
> So if I would do:
>
> 1 g_module_open(my-lib)
> 2 Load symbols, use my library...
> 3 g_module_close(my-lib)
> 4 Make modifications to my library and reload it:
> 5 g_module_open(my-lib)
>
> Then the library was not really reloaded, and the old instance would
> still be used.

Glib does do reference counting so it won't unload the module until all
references have been dropped. Did you check the return value from the
g_module_close()?


> This did not happen when I used dlopen/dlclose.
> Do we have a way to force 'g_module_close' to unload the library?

On POSIX the underlying mechanism is dlclose() anyway. You can also
check g_module_error() to see if there was an error unloading.

>
> Thanks, Paz
>
> -------------------------------------------------------------------------------------------------------------------------
> From: Peter Maydell <peter.maydell@linaro.org>
> Sent: Thursday, February 29, 2024 7:34 PM
> To: Paz Offer <poffer@nvidia.com>
> Cc: qemu-devel@nongnu.org <qemu-devel@nongnu.org>
> Subject: Re: What is the correct way to add linker dependency to QEMU build system? 
>  
> External email: Use caution opening links or attachments
>
> On Thu, 29 Feb 2024 at 16:10, Paz Offer <poffer@nvidia.com> wrote:
>> I want to add library 'libdl' to be linked with QEMU build for a particular target (e.g. - qemu-system-arm).
>> Using meson I would typically do 'compiler.find_library(...)', and later add the returned dependency to the binary
> dependencies list.
>> However, in QEMU I understand that these configurations are done in the './configure' file?
>>
>> What would be the correct way to do this?
>
> If you can do the job using the glib g_module_open()/
> g_module_symbol() functions (which is how QEMU itself does
> loading of plugin and module DLLs, and which on Unix hosts
> are pretty much wrappers around dlopen/dlsym) then you
> don't need to link against libdl at all.
>
> If this is for something you're planning to upstream
> then it might be worth talking at a higher level about
> what you're aiming to do. (If it's for something downstream
> that you don't plan to ever upstream then you can do
> whatever's easiest for you, of course.)
>
> -- PMM

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


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

end of thread, other threads:[~2024-03-06  9:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-29 16:09 What is the correct way to add linker dependency to QEMU build system? Paz Offer
2024-02-29 17:02 ` Alex Bennée
2024-02-29 21:22   ` Paolo Bonzini
2024-02-29 17:34 ` Peter Maydell
2024-02-29 19:00   ` Paz Offer
2024-03-06  6:05   ` Paz Offer
2024-03-06  9:28     ` Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.