Bug 23543

Summary: when linked without -lpthread, sem_timedwait will be fail
Product: glibc Reporter: hehongjun <He.Hongjun>
Component: nptlAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: drepper.fsp, fweimer
Priority: P2 Flags: fweimer: security-
Version: 2.30   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: call sem_timedwait failed

Description hehongjun 2018-08-17 09:10:55 UTC
Created attachment 11191 [details]
call sem_timedwait failed

when act like below:
1. calling sem_timedwait in shared lib, and the shrared lib linked without -lpthread;
2. the main program linked with -lptherad;
then, the sem_timedwait is failed.

this happend on x86 and mips.
 
the sample:
sem_mai.c
#include <stdio.h>

extern void testsem();

int main()
{
  printf("=== main start\n");
  testsem();
  printf("=== end\n");
}
Comment 1 Florian Weimer 2018-08-17 12:01:05 UTC
See bug 20489 comment 16.  Objects need to be linked at the right library, or otherwise the symbol version information will be missing.

*** This bug has been marked as a duplicate of bug 20489 ***
Comment 2 hehongjun 2018-08-20 01:04:02 UTC
(In reply to Florian Weimer from comment #1)
> See bug 20489 comment 16.  Objects need to be linked at the right library,
> or otherwise the symbol version information will be missing.
> 
> *** This bug has been marked as a duplicate of bug 20489 ***

  sometimes, we hope the DSO haveing no the symbol version, then it can run on different environment.
  I think the  sem_timedwait need to  fix.
  the reason are:
  1. the compatibility sem_init use old_sem structure;
  2. the sem_timedwait use new_sem structure;
  3. in https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/nptl/internaltypes.h;h=7c0d2402a3a68eec0b9849e4b6b52287f65d3f54;hb=042e1521c794a945edc43b5bfa7e69ad70420524, the new_sem have changed. Wait flag bit has be added to the value field.
  so, the sem_timedwait needs compatibility version symbol useing old_sem structure.
Comment 3 Florian Weimer 2018-08-20 07:10:35 UTC
Sorry, the DSO is simply broken.  It is quite literally calling the wrong function.