All of lore.kernel.org
 help / color / mirror / Atom feed
* horribly wrong code when --with-versioned is active
@ 2013-08-05 21:46 John Spencer
  2013-08-06  5:57 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: John Spencer @ 2013-08-05 21:46 UTC (permalink / raw)
  To: alsa-devel

if --with-versioned is active (default), a couple of macros in pcm.c
start generating some completely broken, __old-prefixed wrapper 
functions, which then are getting used whenever the actual function is 
called.

for example:
snd_pcm_hw_params_set_buffer_time_near

__OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);

->

#define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)

->

#define __P_OLD_NEAR1(pfx, name, ret_type) \
ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type 
val, int *dir) \
{ \
         if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
                 return 0; \
         return (ret_type)val; \
}

this will lead to generating a function 
__old_snd_pcm_hw_params_set_buffer_time_near which expands to

unsigned int __old_snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t 
*pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir)
{
         if snd1_pcm_hw_params_set_buffer_time_near(pcm, params, &val, 
dir) < 0)
                 return 0;
         return (ret_type)val;
}

there 2 bugs in there,
1) the real function gets passed a pointer to a pointer of unsigned, 
which is then happily dereferenced and the original pointer used as an 
int, and
2) the return type logic is wrong, in case of a non-error, the original 
pointer will be returned instead of 0 to indicate success.

the right fix would look something like this:

@@ -7190,19 +7192,15 @@
  __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned 
int);

  #define __P_OLD_NEAR(pfx, name, ret_type) \
-ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, 
ret_type val) \
+ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, 
ret_type *val) \
  { \
-	if (INTERNAL(name)(pcm, params, &val) < 0) \
-		return 0; \
-	return (ret_type)val; \
+	return(INTERNAL(name)(pcm, params, val)); \
  }

  #define __P_OLD_NEAR1(pfx, name, ret_type) \
-ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, 
ret_type val, int *dir) \
+ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, 
ret_type *val, int *dir) \
  { \
-	if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
-		return 0; \
-	return (ret_type)val; \
+	return (INTERNAL(name)(pcm, params, val, dir) < 0); \
  }

  #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)


this is only half of the fix though, the "old" getter functions seem to 
misbehave as well. the misbehaviour can be inspected by using a small 
openal-soft (version 1.14) example code, and breaking on 
alsa_reset_playback and single stepping through the invocation of 
CHECK(snd_pcm_hw_params_set_buffer_time_near(data->pcmHandle, hp, 
&bufferLen, NULL));

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

* Re: horribly wrong code when --with-versioned is active
  2013-08-05 21:46 horribly wrong code when --with-versioned is active John Spencer
@ 2013-08-06  5:57 ` Takashi Iwai
  2013-08-06 15:51   ` John Spencer
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2013-08-06  5:57 UTC (permalink / raw)
  To: John Spencer; +Cc: alsa-devel

At Mon, 05 Aug 2013 23:46:09 +0200,
John Spencer wrote:
> 
> if --with-versioned is active (default), a couple of macros in pcm.c
> start generating some completely broken, __old-prefixed wrapper 
> functions, which then are getting used whenever the actual function is 
> called.
> 
> for example:
> snd_pcm_hw_params_set_buffer_time_near
> 
> __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
> 
> ->
> 
> #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
> 
> ->
> 
> #define __P_OLD_NEAR1(pfx, name, ret_type) \
> ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type 
> val, int *dir) \
> { \
>          if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
>                  return 0; \
>          return (ret_type)val; \
> }
> 
> this will lead to generating a function 
> __old_snd_pcm_hw_params_set_buffer_time_near which expands to
> 
> unsigned int __old_snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t 
> *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir)
> {
>          if snd1_pcm_hw_params_set_buffer_time_near(pcm, params, &val, 
> dir) < 0)
>                  return 0;
>          return (ret_type)val;
> }
> 
> there 2 bugs in there,
> 1) the real function gets passed a pointer to a pointer of unsigned, 
> which is then happily dereferenced and the original pointer used as an 
> int, and

The pointer cast between signed and unsigned is done normally in C.

> 2) the return type logic is wrong, in case of a non-error, the original 
> pointer will be returned instead of 0 to indicate success.

The val argument is no pointer but a value.


Takashi

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

* Re: horribly wrong code when --with-versioned is active
  2013-08-06  5:57 ` Takashi Iwai
@ 2013-08-06 15:51   ` John Spencer
  2013-08-07  6:13     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: John Spencer @ 2013-08-06 15:51 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

On 08/06/2013 07:57 AM, Takashi Iwai wrote:
> At Mon, 05 Aug 2013 23:46:09 +0200,
> John Spencer wrote:
>>
>> if --with-versioned is active (default), a couple of macros in pcm.c
>> start generating some completely broken, __old-prefixed wrapper
>> functions, which then are getting used whenever the actual function is
>> called.
>>
>> for example:
>> snd_pcm_hw_params_set_buffer_time_near
>>
>> __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
>>
>> ->
>>
>> #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
>>
>> ->
>>
>> #define __P_OLD_NEAR1(pfx, name, ret_type) \
>> ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type
>> val, int *dir) \
>> { \
>>           if (INTERNAL(name)(pcm, params,&val, dir)<  0) \
>>                   return 0; \
>>           return (ret_type)val; \
>> }
>>
>> this will lead to generating a function
>> __old_snd_pcm_hw_params_set_buffer_time_near which expands to
>>
>> unsigned int __old_snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t
>> *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir)
>> {
>>           if snd1_pcm_hw_params_set_buffer_time_near(pcm, params,&val,
>> dir)<  0)
>>                   return 0;
>>           return (ret_type)val;
>> }
>>
>> there 2 bugs in there,
>> 1) the real function gets passed a pointer to a pointer of unsigned,
>> which is then happily dereferenced and the original pointer used as an
>> int, and
>
> The pointer cast between signed and unsigned is done normally in C.
>
>> 2) the return type logic is wrong, in case of a non-error, the original
>> pointer will be returned instead of 0 to indicate success.
>
> The val argument is no pointer but a value.

my problem is that the old version is getting called instead of the new one.

so it passes a pointer where an int is expected. maybe that's because 
openal uses dlopen to open the alsa DSO. or it is due to some binutils 
bug or whatever.

anyway, since this all looks very hackish and fragile, and given that 
the change old api -> new api was done 11 years ago, can we agree to 
just remove the old cruft and debloat alsa-lib slightly by doing so ?
i'm pretty sure *nobody* is using the old stuff anymore.

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

* Re: horribly wrong code when --with-versioned is active
  2013-08-06 15:51   ` John Spencer
@ 2013-08-07  6:13     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2013-08-07  6:13 UTC (permalink / raw)
  To: John Spencer; +Cc: alsa-devel

At Tue, 06 Aug 2013 17:51:55 +0200,
John Spencer wrote:
> 
> On 08/06/2013 07:57 AM, Takashi Iwai wrote:
> > At Mon, 05 Aug 2013 23:46:09 +0200,
> > John Spencer wrote:
> >>
> >> if --with-versioned is active (default), a couple of macros in pcm.c
> >> start generating some completely broken, __old-prefixed wrapper
> >> functions, which then are getting used whenever the actual function is
> >> called.
> >>
> >> for example:
> >> snd_pcm_hw_params_set_buffer_time_near
> >>
> >> __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
> >>
> >> ->
> >>
> >> #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
> >>
> >> ->
> >>
> >> #define __P_OLD_NEAR1(pfx, name, ret_type) \
> >> ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type
> >> val, int *dir) \
> >> { \
> >>           if (INTERNAL(name)(pcm, params,&val, dir)<  0) \
> >>                   return 0; \
> >>           return (ret_type)val; \
> >> }
> >>
> >> this will lead to generating a function
> >> __old_snd_pcm_hw_params_set_buffer_time_near which expands to
> >>
> >> unsigned int __old_snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t
> >> *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir)
> >> {
> >>           if snd1_pcm_hw_params_set_buffer_time_near(pcm, params,&val,
> >> dir)<  0)
> >>                   return 0;
> >>           return (ret_type)val;
> >> }
> >>
> >> there 2 bugs in there,
> >> 1) the real function gets passed a pointer to a pointer of unsigned,
> >> which is then happily dereferenced and the original pointer used as an
> >> int, and
> >
> > The pointer cast between signed and unsigned is done normally in C.
> >
> >> 2) the return type logic is wrong, in case of a non-error, the original
> >> pointer will be returned instead of 0 to indicate success.
> >
> > The val argument is no pointer but a value.
> 
> my problem is that the old version is getting called instead of the new one.
> 
> so it passes a pointer where an int is expected. maybe that's because 
> openal uses dlopen to open the alsa DSO. or it is due to some binutils 
> bug or whatever.

openal explicitly tries to load the versioned symbols, IIRC.

> anyway, since this all looks very hackish and fragile, and given that 
> the change old api -> new api was done 11 years ago, can we agree to 
> just remove the old cruft and debloat alsa-lib slightly by doing so ?
> i'm pretty sure *nobody* is using the old stuff anymore.

Probatio diabolica :)

And, even if you remove the old code, the versioned symbols must
remain as is.  Some applications do load the versioned symbols
explicitly, thus removing the versions breaks ABI.  So, just removing
it is no-go.

If you have some patch to achieve the old code optional
(e.g. selectable via a configure option) and still keep the ABI, it'd
be greatly appreciated.


Takashi

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

end of thread, other threads:[~2013-08-07  6:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-05 21:46 horribly wrong code when --with-versioned is active John Spencer
2013-08-06  5:57 ` Takashi Iwai
2013-08-06 15:51   ` John Spencer
2013-08-07  6:13     ` Takashi Iwai

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.