mailing list of musl libc
 help / color / mirror / code / Atom feed
* Static linking of musl with code compiled using GNU header files
@ 2014-03-14 15:47 David Grothe
  2014-03-14 16:09 ` Luca Barbato
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: David Grothe @ 2014-03-14 15:47 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

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

Hello,

I have a very large code base that I have been compiling on Linux using 
the standard GNU C compiler [gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3].  
I have been using shared object libraries, but for reasons of software 
support I would now like to link all my commands (a couple of dozen) and 
daemons using static libraries so that the code files are self-contained 
and can be copied, along with a core file, to any server back in my shop 
for analysis.  With dynamic libraries I have to have exactly the same 
version of libc installed on the machine that I use to examine the core 
file as were present on the machine that generated the core file, or 
else gdb will not produce a stack back trace with file and line number 
information.  So much for the background.

I really don't want to port my code base to using the musl header 
files.  I want to keep compiling with the GNU headers.  When I do this 
and link my-huge-program.o with musl libc.a I get the following list of 
unresolved externals:

          U __divdi3
          w __fini_array_end
          w __fini_array_start
          U __moddi3
          U __sysv_signal
          U __udivdi3
          U __umoddi3
          U __vfprintf_chk
          U __vsnprintf_chk
          U __vsprintf_chk
          U __sysv_signal

So, I am wondering if the musl library could at some point provide these 
routines to enable users to do what I am trying to do.

Any possibility of that?

Thanks,
Dave

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

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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 15:47 Static linking of musl with code compiled using GNU header files David Grothe
@ 2014-03-14 16:09 ` Luca Barbato
  2014-03-14 16:29 ` Szabolcs Nagy
  2014-03-14 16:47 ` Rich Felker
  2 siblings, 0 replies; 11+ messages in thread
From: Luca Barbato @ 2014-03-14 16:09 UTC (permalink / raw)
  To: musl

On 14/03/14 16:47, David Grothe wrote:
> I really don't want to port my code base to using the musl header
> files. 

There shouldn't be anything to port.

> I want to keep compiling with the GNU headers.  When I do this
> and link my-huge-program.o with musl libc.a I get the following list of
> unresolved externals:
> 
>          U __divdi3
>          w __fini_array_end
>          w __fini_array_start
>          U __moddi3
>          U __sysv_signal
>          U __udivdi3
>          U __umoddi3

>          U __vfprintf_chk
>          U __vsnprintf_chk
>          U __vsprintf_chk

>          U __sysv_signal
> 
> So, I am wondering if the musl library could at some point provide these
> routines to enable users to do what I am trying to do.

Not sure, but those internal symbols are close to implementation details...

lu



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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 15:47 Static linking of musl with code compiled using GNU header files David Grothe
  2014-03-14 16:09 ` Luca Barbato
@ 2014-03-14 16:29 ` Szabolcs Nagy
  2014-03-14 18:52   ` David Grothe
  2014-03-14 16:47 ` Rich Felker
  2 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2014-03-14 16:29 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

* David Grothe <dave@gcom.com> [2014-03-14 10:47:31 -0500]:
> I have a very large code base that I have been compiling on Linux
> using the standard GNU C compiler [gcc (Ubuntu/Linaro
> 4.6.3-1ubuntu5) 4.6.3].  I have been using shared object libraries,
> but for reasons of software support I would now like to link all my
> commands (a couple of dozen) and daemons using static libraries so
> that the code files are self-contained and can be copied, along with
> a core file, to any server back in my shop for analysis.  With
> dynamic libraries I have to have exactly the same version of libc
> installed on the machine that I use to examine the core file as were
> present on the machine that generated the core file, or else gdb
> will not produce a stack back trace with file and line number
> information.  So much for the background.
> 
> I really don't want to port my code base to using the musl header
> files.  I want to keep compiling with the GNU headers.  When I do

compiling with the gnu headers is broken and
it depends on the cflags used

> this and link my-huge-program.o with musl libc.a I get the following
> list of unresolved externals:
> 
>          U __divdi3

comes from libgcc.a, if it's missing you have a toolchain issue

>          w __fini_array_end
>          w __fini_array_start

i think musl supports init/fini arrays
(see src/exit/exit.c)

>          U __moddi3

libgcc

>          U __sysv_signal

you may want to replace it with signal

>          U __udivdi3
>          U __umoddi3

libgcc

>          U __vfprintf_chk
>          U __vsnprintf_chk
>          U __vsprintf_chk

there are many _chk functions for _FORTIFY_SOURCE, musl may provide
these eventually, until then you can add your own chk.o with dummy
implementations (possibly with the safety checks i omit here):

int __vfprintf_chk(FILE *f, int flag, const char *fmt, va_list ap)
{
	return vfprintf(f, fmt, ap);
}
int __vsnprintf_chk(char *s, size_t n, int flag, size_t size, const char *fmt, va_list ap)
{
	return vsnprintf(s, n, fmt, ap);
}
int __vsprintf_chk(char *s, int flag, size_t size, const char *fmt, va_list ap)
{
	return vsprintf(s, fmt, ap);
}

>          U __sysv_signal

use signal

> So, I am wondering if the musl library could at some point provide
> these routines to enable users to do what I am trying to do.

compiling with glibc headers and then linking to musl
cannot be supported in general, because of ABI compat issues

(eg glibc headers define PTHREAD_*_INITIALIZER macros that hardcode
glibc internal ABI at compile time that does not match musl)

if you are sure you don't have such ABI breakage (see glibc
vs musl differences on the wiki) then you may get away by
adding a glibc-compat.o to your musl build

> 
> Any possibility of that?
> 
> Thanks,
> Dave


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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 15:47 Static linking of musl with code compiled using GNU header files David Grothe
  2014-03-14 16:09 ` Luca Barbato
  2014-03-14 16:29 ` Szabolcs Nagy
@ 2014-03-14 16:47 ` Rich Felker
  2 siblings, 0 replies; 11+ messages in thread
From: Rich Felker @ 2014-03-14 16:47 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

On Fri, Mar 14, 2014 at 10:47:31AM -0500, David Grothe wrote:
> Hello,
> 
> I have a very large code base that I have been compiling on Linux
> using the standard GNU C compiler [gcc (Ubuntu/Linaro
> 4.6.3-1ubuntu5) 4.6.3].  I have been using shared object libraries,
> but for reasons of software support I would now like to link all my
> commands (a couple of dozen) and daemons using static libraries so
> that the code files are self-contained and can be copied, along with
> a core file, to any server back in my shop for analysis.  With
> dynamic libraries I have to have exactly the same version of libc
> installed on the machine that I use to examine the core file as were
> present on the machine that generated the core file, or else gdb
> will not produce a stack back trace with file and line number
> information.  So much for the background.
> 
> I really don't want to port my code base to using the musl header
> files.  I want to keep compiling with the GNU headers.  When I do
> this and link my-huge-program.o with musl libc.a I get the following
> list of unresolved externals:
> 
>          U __divdi3
>          w __fini_array_end
>          w __fini_array_start
>          U __moddi3
>          U __sysv_signal
>          U __udivdi3
>          U __umoddi3
>          U __vfprintf_chk
>          U __vsnprintf_chk
>          U __vsprintf_chk
>          U __sysv_signal

The presence of __divdi3, __moddi3, __udivdi3, and __umoddi3 in this
list indicates that you're missing libgcc.a. If you're using
-nostdlib, you need to manually add libgcc back to the linker command
line. __fini_array_start and __fini_array_end are provided by the
linker and are not necessary unless your code has global destructors
that the compiler is implementing via fini_array (this is why they're
weak).

The rest are __sysv_signal and __*_chk. The former looks suspicious: I
really doubt you _want_ to be using the sysv version of signal(); it
probably got pulled in by glibc's headers due to bad feature test
macros or something. As for the latter, these come from
_FORTIFY_SOURCE which musl does not yet support.

> So, I am wondering if the musl library could at some point provide
> these routines to enable users to do what I am trying to do.
> 
> Any possibility of that?

Likely for at least some of them, but not right away. And there are at
least a few features (e.g. pthread cancellation) that will never work
this way.

BTW is there a reason you want to use glibc's headers with musl? If
your program is having lots of build errors with musl's, it's probably
indicative of problems you should fix; some of these problems may
become problems with future glibc versions too.

Rich


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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 16:29 ` Szabolcs Nagy
@ 2014-03-14 18:52   ` David Grothe
  2014-03-14 19:25     ` Kurt H Maier
  2014-03-14 21:04     ` David Grothe
  0 siblings, 2 replies; 11+ messages in thread
From: David Grothe @ 2014-03-14 18:52 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

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

Thanks for the suggestions.

My musl build did not include a libgcc:

linuxsvr:dave:musl-0.9.15> find . -name '*libgcc*'
linuxsvr:dave:musl-0.9.15>

It is correct that something in the GNU headers changed "signal" into 
"sysv_signal" without my knowledge.

My code base is several million lines of code and I have many other 
projects to do that are higher priority than porting to another set of 
header files.  It would be a few days worth of effort and I just have 
other things to do right now.

That said I do have a reason for wanting static linking, so maybe I will 
find the time to do the port some time. (I tried just aiming my build at 
the musl include directory and it did not "just work".)

I can act on the suggestions made and see how that helps.  But what 
about libgcc?

Thanks,
Dave

On 3/14/2014 11:29 AM, Szabolcs Nagy wrote:
> * David Grothe <dave@gcom.com> [2014-03-14 10:47:31 -0500]:
>> I have a very large code base that I have been compiling on Linux
>> using the standard GNU C compiler [gcc (Ubuntu/Linaro
>> 4.6.3-1ubuntu5) 4.6.3].  I have been using shared object libraries,
>> but for reasons of software support I would now like to link all my
>> commands (a couple of dozen) and daemons using static libraries so
>> that the code files are self-contained and can be copied, along with
>> a core file, to any server back in my shop for analysis.  With
>> dynamic libraries I have to have exactly the same version of libc
>> installed on the machine that I use to examine the core file as were
>> present on the machine that generated the core file, or else gdb
>> will not produce a stack back trace with file and line number
>> information.  So much for the background.
>>
>> I really don't want to port my code base to using the musl header
>> files.  I want to keep compiling with the GNU headers.  When I do
> compiling with the gnu headers is broken and
> it depends on the cflags used
>
>> this and link my-huge-program.o with musl libc.a I get the following
>> list of unresolved externals:
>>
>>           U __divdi3
> comes from libgcc.a, if it's missing you have a toolchain issue
>
>>           w __fini_array_end
>>           w __fini_array_start
> i think musl supports init/fini arrays
> (see src/exit/exit.c)
>
>>           U __moddi3
> libgcc
>
>>           U __sysv_signal
> you may want to replace it with signal
>
>>           U __udivdi3
>>           U __umoddi3
> libgcc
>
>>           U __vfprintf_chk
>>           U __vsnprintf_chk
>>           U __vsprintf_chk
> there are many _chk functions for _FORTIFY_SOURCE, musl may provide
> these eventually, until then you can add your own chk.o with dummy
> implementations (possibly with the safety checks i omit here):
>
> int __vfprintf_chk(FILE *f, int flag, const char *fmt, va_list ap)
> {
> 	return vfprintf(f, fmt, ap);
> }
> int __vsnprintf_chk(char *s, size_t n, int flag, size_t size, const char *fmt, va_list ap)
> {
> 	return vsnprintf(s, n, fmt, ap);
> }
> int __vsprintf_chk(char *s, int flag, size_t size, const char *fmt, va_list ap)
> {
> 	return vsprintf(s, fmt, ap);
> }
>
>>           U __sysv_signal
> use signal
>
>> So, I am wondering if the musl library could at some point provide
>> these routines to enable users to do what I am trying to do.
> compiling with glibc headers and then linking to musl
> cannot be supported in general, because of ABI compat issues
>
> (eg glibc headers define PTHREAD_*_INITIALIZER macros that hardcode
> glibc internal ABI at compile time that does not match musl)
>
> if you are sure you don't have such ABI breakage (see glibc
> vs musl differences on the wiki) then you may get away by
> adding a glibc-compat.o to your musl build
>
>> Any possibility of that?
>>
>> Thanks,
>> Dave


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

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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 18:52   ` David Grothe
@ 2014-03-14 19:25     ` Kurt H Maier
  2014-03-14 19:35       ` David Grothe
  2014-03-14 21:04     ` David Grothe
  1 sibling, 1 reply; 11+ messages in thread
From: Kurt H Maier @ 2014-03-14 19:25 UTC (permalink / raw)
  To: musl

Quoting David Grothe <dave@gcom.com>:

> My musl build did not include a libgcc:

libgcc comes with gcc.

http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

khm





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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 19:25     ` Kurt H Maier
@ 2014-03-14 19:35       ` David Grothe
  0 siblings, 0 replies; 11+ messages in thread
From: David Grothe @ 2014-03-14 19:35 UTC (permalink / raw)
  To: musl

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

Got it.  Thanks.
-- Dave

On 3/14/2014 2:25 PM, Kurt H Maier wrote:
> Quoting David Grothe <dave@gcom.com>:
>
>> My musl build did not include a libgcc:
>
> libgcc comes with gcc.
>
> http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
>
> khm
>
>
>


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

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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 18:52   ` David Grothe
  2014-03-14 19:25     ` Kurt H Maier
@ 2014-03-14 21:04     ` David Grothe
  2014-03-14 21:37       ` John Spencer
  2014-03-15  0:22       ` Rich Felker
  1 sibling, 2 replies; 11+ messages in thread
From: David Grothe @ 2014-03-14 21:04 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

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

I built a shim module that defined all the undefined "__" routines that 
showed up in my link.  Then all my programs linked successfully.  But 
when I went to run one of my daemon processes it got a segv in the 
malloc code, as follows.

Program terminated with signal 11, Segmentation fault.
#0  0x0811cd5d in unbin (c=0x9b53898, i=8) at src/malloc/malloc.c:242
#1  0x0811d266 in malloc (n=112) at src/malloc/malloc.c:371
#2  0x0804b3ce in ssd_malloc_fcn (nbytes=16, file=0x81348e6 "../pi.c", 
linenr=2398) at ../pi.c:632
#3  0x0804b597 in ssd_zalloc_fcn (nbytes=12, file=0x81348e6 "../pi.c", 
linenr=2398) at ../pi.c:687
#4  0x0804b5e2 in ssd_calloc_fcn (n_memb=1, memb_size=12, file=0x81348e6 
"../pi.c", linenr=2398) at ../pi.c:696
#5  0x0804ef18 in ss_setup_code_path (size=1024) at ../pi.c:2398
#6  0x080548be in register_connections () at ../pi.c:5074
#7  0x0805a2b8 in main (argc=2, argv=0xbfae15f4) at ../pi.c:7393
(gdb) p *c
$1 = {psize = 17, csize = 144, next = 0x81a3990, prev = 0x1}
(gdb) p mal
$2 = {brk = 163028992, heap = 0x9b53008, binmap = 35184372089088, bins = 
{{lock = {0, 0}, head = 0x0, tail = 0x0}, {lock = {0, 0}, head = 
0x81a3920, tail = 0x81a3920}, {lock = {0, 0},
       head = 0x81a3930, tail = 0x81a3930}, {lock = {0, 0}, head = 
0x81a3940, tail = 0x81a3940}, {lock = {0, 0}, head = 0x0, tail = 0x0}, 
{lock = {0, 0}, head = 0x81a3960, tail = 0x81a3960}, {
       lock = {0, 0}, head = 0x81a3970, tail = 0x81a3970}, {lock = {0, 
0}, head = 0x81a3980, tail = 0x81a3980}, {lock = {0, 0}, head = 
0x9b53898, tail = 0x9b53898}, {lock = {0, 0},
       head = 0x81a39a0, tail = 0x81a39a0}, {lock = {0, 0}, head = 
0x81a39b0, tail = 0x81a39b0}, {lock = {0, 0}, head = 0x81a39c0, tail = 
0x81a39c0}, {lock = {0, 0}, head = 0x81a39d0,
       tail = 0x81a39d0}, {lock = {0, 0}, head = 0x81a39e0, tail = 
0x81a39e0}, {lock = {0, 0}, head = 0x81a39f0, tail = 0x81a39f0}, {lock = 
{0, 0}, head = 0x81a3a00, tail = 0x81a3a00}, {lock = {0,
         0}, head = 0x81a3a10, tail = 0x81a3a10}, {lock = {0, 0}, head = 
0x0, tail = 0x0}, {lock = {0, 0}, head = 0x81a3a30, tail = 0x81a3a30}, 
{lock = {0, 0}, head = 0x81a3a40, tail = 0x81a3a40},
     {lock = {0, 0}, head = 0x81a3a50, tail = 0x81a3a50}, {lock = {0, 
0}, head = 0x81a3a60, tail = 0x81a3a60}, {lock = {0, 0}, head = 0x0, 
tail = 0x0}, {lock = {0, 0}, head = 0x81a3a80,
       tail = 0x81a3a80}, {lock = {0, 0}, head = 0x81a3a90, tail = 
0x81a3a90}, {lock = {0, 0}, head = 0x81a3aa0, tail = 0x81a3aa0}, {lock = 
{0, 0}, head = 0x0, tail = 0x0}, {lock = {0, 0},
       head = 0x81a3ac0, tail = 0x81a3ac0}, {lock = {0, 0}, head = 
0x81a3ad0, tail = 0x81a3ad0}, {lock = {0, 0}, head = 0x81a3ae0, tail = 
0x81a3ae0}, {lock = {0, 0}, head = 0x81a3af0,
       tail = 0x81a3af0}, {lock = {0, 0}, head = 0x0, tail = 0x0}, {lock 
= {0, 0}, head = 0x81a3b10, tail = 0x81a3b10}, {lock = {0, 0}, head = 
0x81a3b20, tail = 0x81a3b20}, {lock = {0, 0},
       head = 0x81a3b30, tail = 0x81a3b30}, {lock = {0, 0}, head = 
0x81a3b40, tail = 0x81a3b40}, {lock = {0, 0}, head = 0x81a3b50, tail = 
0x81a3b50}, {lock = {0, 0}, head = 0x81a3b60,
       tail = 0x81a3b60}, {lock = {0, 0}, head = 0x81a3b70, tail = 
0x81a3b70}, {lock = {0, 0}, head = 0x81a3b80, tail = 0x81a3b80}, {lock = 
{0, 0}, head = 0x81a3b90, tail = 0x81a3b90}, {lock = {0,
         0}, head = 0x81a3ba0, tail = 0x81a3ba0}, {lock = {0, 0}, head = 
0x81a3bb0, tail = 0x81a3bb0}, {lock = {0, 0}, head = 0x81a3bc0, tail = 
0x81a3bc0}, {lock = {0, 0}, head = 0x81a3bd0,
       tail = 0x81a3bd0}, {lock = {0, 0}, head = 0x9b78888, tail = 
0x9b78888}, {lock = {0, 0}, head = 0x81a3bf0, tail = 0x81a3bf0}, {lock = 
{0, 0}, head = 0x0, tail = 0x0} <repeats 17 times>},
   brk_lock = {0, 0}, free_lock = {0, 0}}


I can supply more details as needed.
Thanks,
Dave


On 3/14/2014 1:52 PM, David Grothe wrote:
> Thanks for the suggestions.
>
> My musl build did not include a libgcc:
>
> linuxsvr:dave:musl-0.9.15> find . -name '*libgcc*'
> linuxsvr:dave:musl-0.9.15>
>
> It is correct that something in the GNU headers changed "signal" into 
> "sysv_signal" without my knowledge.
>
> My code base is several million lines of code and I have many other 
> projects to do that are higher priority than porting to another set of 
> header files.  It would be a few days worth of effort and I just have 
> other things to do right now.
>
> That said I do have a reason for wanting static linking, so maybe I 
> will find the time to do the port some time. (I tried just aiming my 
> build at the musl include directory and it did not "just work".)
>
> I can act on the suggestions made and see how that helps.  But what 
> about libgcc?
>
> Thanks,
> Dave
>
> On 3/14/2014 11:29 AM, Szabolcs Nagy wrote:
>> * David Grothe<dave@gcom.com>  [2014-03-14 10:47:31 -0500]:
>>> I have a very large code base that I have been compiling on Linux
>>> using the standard GNU C compiler [gcc (Ubuntu/Linaro
>>> 4.6.3-1ubuntu5) 4.6.3].  I have been using shared object libraries,
>>> but for reasons of software support I would now like to link all my
>>> commands (a couple of dozen) and daemons using static libraries so
>>> that the code files are self-contained and can be copied, along with
>>> a core file, to any server back in my shop for analysis.  With
>>> dynamic libraries I have to have exactly the same version of libc
>>> installed on the machine that I use to examine the core file as were
>>> present on the machine that generated the core file, or else gdb
>>> will not produce a stack back trace with file and line number
>>> information.  So much for the background.
>>>
>>> I really don't want to port my code base to using the musl header
>>> files.  I want to keep compiling with the GNU headers.  When I do
>> compiling with the gnu headers is broken and
>> it depends on the cflags used
>>
>>> this and link my-huge-program.o with musl libc.a I get the following
>>> list of unresolved externals:
>>>
>>>           U __divdi3
>> comes from libgcc.a, if it's missing you have a toolchain issue
>>
>>>           w __fini_array_end
>>>           w __fini_array_start
>> i think musl supports init/fini arrays
>> (see src/exit/exit.c)
>>
>>>           U __moddi3
>> libgcc
>>
>>>           U __sysv_signal
>> you may want to replace it with signal
>>
>>>           U __udivdi3
>>>           U __umoddi3
>> libgcc
>>
>>>           U __vfprintf_chk
>>>           U __vsnprintf_chk
>>>           U __vsprintf_chk
>> there are many _chk functions for _FORTIFY_SOURCE, musl may provide
>> these eventually, until then you can add your own chk.o with dummy
>> implementations (possibly with the safety checks i omit here):
>>
>> int __vfprintf_chk(FILE *f, int flag, const char *fmt, va_list ap)
>> {
>> 	return vfprintf(f, fmt, ap);
>> }
>> int __vsnprintf_chk(char *s, size_t n, int flag, size_t size, const char *fmt, va_list ap)
>> {
>> 	return vsnprintf(s, n, fmt, ap);
>> }
>> int __vsprintf_chk(char *s, int flag, size_t size, const char *fmt, va_list ap)
>> {
>> 	return vsprintf(s, fmt, ap);
>> }
>>
>>>           U __sysv_signal
>> use signal
>>
>>> So, I am wondering if the musl library could at some point provide
>>> these routines to enable users to do what I am trying to do.
>> compiling with glibc headers and then linking to musl
>> cannot be supported in general, because of ABI compat issues
>>
>> (eg glibc headers define PTHREAD_*_INITIALIZER macros that hardcode
>> glibc internal ABI at compile time that does not match musl)
>>
>> if you are sure you don't have such ABI breakage (see glibc
>> vs musl differences on the wiki) then you may get away by
>> adding a glibc-compat.o to your musl build
>>
>>> Any possibility of that?
>>>
>>> Thanks,
>>> Dave
>


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

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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 21:04     ` David Grothe
@ 2014-03-14 21:37       ` John Spencer
  2014-03-15  0:09         ` Rich Felker
  2014-03-15  0:22       ` Rich Felker
  1 sibling, 1 reply; 11+ messages in thread
From: John Spencer @ 2014-03-14 21:37 UTC (permalink / raw)
  To: musl

David Grothe wrote:
> I built a shim module that defined all the undefined "__" routines that 
> showed up in my link.  Then all my programs linked successfully.  But 
> when I went to run one of my daemon processes it got a segv in the 
> malloc code, as follows.

on which platform is this ? the linaro bit in your toolchain suggests 
that it is ARM. is that correct ? and which version of musl ?
limited ABI compat is only there for x86 platforms.

as for your problem below, it's possible that something else calls 
sbrk() messing up musl's allocator.
you should check strace output to see if sbrk(0) is called more than once.
also make sure that nothing pulls in glibc's libc.so.

btw did you check your code against the ABI checklist that was pointed 
out earlier ?

to me, it's not very surprising that your broken usage breaks and 
invokes UB somewhere..

> 
> Program terminated with signal 11, Segmentation fault.
> #0  0x0811cd5d in unbin (c=0x9b53898, i=8) at src/malloc/malloc.c:242
> #1  0x0811d266 in malloc (n=112) at src/malloc/malloc.c:371
> #2  0x0804b3ce in ssd_malloc_fcn (nbytes=16, file=0x81348e6 "../pi.c", 
> linenr=2398) at ../pi.c:632
> #3  0x0804b597 in ssd_zalloc_fcn (nbytes=12, file=0x81348e6 "../pi.c", 
> linenr=2398) at ../pi.c:687
> #4  0x0804b5e2 in ssd_calloc_fcn (n_memb=1, memb_size=12, file=0x81348e6 


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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 21:37       ` John Spencer
@ 2014-03-15  0:09         ` Rich Felker
  0 siblings, 0 replies; 11+ messages in thread
From: Rich Felker @ 2014-03-15  0:09 UTC (permalink / raw)
  To: musl

On Fri, Mar 14, 2014 at 10:37:08PM +0100, John Spencer wrote:
> David Grothe wrote:
> >I built a shim module that defined all the undefined "__" routines
> >that showed up in my link.  Then all my programs linked
> >successfully.  But when I went to run one of my daemon processes
> >it got a segv in the malloc code, as follows.
> 
> on which platform is this ? the linaro bit in your toolchain
> suggests that it is ARM. is that correct ? and which version of musl
> ?
> limited ABI compat is only there for x86 platforms.

While it's untested on anything but x86, the ABI compatibility should
be comparable on arm, mips, microblaze, and sh. OTOH powerpc is known
to be ABI-incompatible for multiple reasons (which basically amount to
the glibc powerpc ABI being really bad) and x86_64 has some minor
incompatibilities due to glibc bugs (regoff_t being the wrong size)
that we'll eventually work around by making the dynamic linker detect
glibc-linked callers and redirect calls to regexec to a fixup wrapper
(but I don't see an easy way to do the same for static linking).

> as for your problem below, it's possible that something else calls
> sbrk() messing up musl's allocator.
> you should check strace output to see if sbrk(0) is called more than once.
> also make sure that nothing pulls in glibc's libc.so.

In latest musl, sbrk is dummied out, so it's probably unlikely that
this is the issue.

> btw did you check your code against the ABI checklist that was
> pointed out earlier ?

From nsz's email? If so, I'm not sure that's quite a "checklist". But
it's important to be aware that trying to rely on the "ABI compat"
will potentially hide problems where your program is using a glibc
feature that musl does not provide. (This would likely be caught at
compile-time if you were using the musl headers, e.g. due to missing
macro constants.)

Rich


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

* Re: Static linking of musl with code compiled using GNU header files
  2014-03-14 21:04     ` David Grothe
  2014-03-14 21:37       ` John Spencer
@ 2014-03-15  0:22       ` Rich Felker
  1 sibling, 0 replies; 11+ messages in thread
From: Rich Felker @ 2014-03-15  0:22 UTC (permalink / raw)
  To: musl; +Cc: Support at Gcom

On Fri, Mar 14, 2014 at 04:04:50PM -0500, David Grothe wrote:
> I built a shim module that defined all the undefined "__" routines
> that showed up in my link.  Then all my programs linked
> successfully.  But when I went to run one of my daemon processes it
> got a segv in the malloc code, as follows.
> 
> Program terminated with signal 11, Segmentation fault.
> #0  0x0811cd5d in unbin (c=0x9b53898, i=8) at src/malloc/malloc.c:242
> #1  0x0811d266 in malloc (n=112) at src/malloc/malloc.c:371
> #2  0x0804b3ce in ssd_malloc_fcn (nbytes=16, file=0x81348e6
> "../pi.c", linenr=2398) at ../pi.c:632
> #3  0x0804b597 in ssd_zalloc_fcn (nbytes=12, file=0x81348e6
> "../pi.c", linenr=2398) at ../pi.c:687
> #4  0x0804b5e2 in ssd_calloc_fcn (n_memb=1, memb_size=12,
> file=0x81348e6 "../pi.c", linenr=2398) at ../pi.c:696
> #5  0x0804ef18 in ss_setup_code_path (size=1024) at ../pi.c:2398
> #6  0x080548be in register_connections () at ../pi.c:5074
> #7  0x0805a2b8 in main (argc=2, argv=0xbfae15f4) at ../pi.c:7393
> (gdb) p *c
> $1 = {psize = 17, csize = 144, next = 0x81a3990, prev = 0x1}

The crashing line is:

        c->prev->next = c->next;

Based on this and your gdb print of *c, it looks like the chunk malloc
is trying to pull from the bin has had its contents (where it stores
its membership in the linked list of free chunks) clobbered, most
likely by your program. This is probably a use-after-free error. At
the very least, c->prev has been clobbered; it's also possible that
c->next was clobbered. You could try printing *c->next to see if it
looks like a valid chunk header (i can tell you if you send it to the
list).

Looking for the code that called free((void *)0x9b538a0) might be a
good way to track this down.

Rich


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

end of thread, other threads:[~2014-03-15  0:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-14 15:47 Static linking of musl with code compiled using GNU header files David Grothe
2014-03-14 16:09 ` Luca Barbato
2014-03-14 16:29 ` Szabolcs Nagy
2014-03-14 18:52   ` David Grothe
2014-03-14 19:25     ` Kurt H Maier
2014-03-14 19:35       ` David Grothe
2014-03-14 21:04     ` David Grothe
2014-03-14 21:37       ` John Spencer
2014-03-15  0:09         ` Rich Felker
2014-03-15  0:22       ` Rich Felker
2014-03-14 16:47 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).