This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug dynamic-link/22299] New: Problem with $PLATFORM on x86_64 platform


https://sourceware.org/bugzilla/show_bug.cgi?id=22299

            Bug ID: 22299
           Summary: Problem with $PLATFORM on x86_64 platform
           Product: glibc
           Version: 2.26
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: valery_reznic at yahoo dot com
  Target Milestone: ---

For glibc 2.26 when running
strace -ELD_PRELOAD='/sss/${PLATFORM}/dddd'  -s300  /bin/cat

I got following output:

execve("/bin/cat", ["/bin/cat"], [/* 32 vars */]) = 0
brk(NULL)                               = 0x556740829000
readlink("/proc/self/exe", "/bin/cat", 4096) = 8
openat(AT_FDCWD, "", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or
directory)
writev(2, [{"ERROR: ld.so: object '", 22}, {"/sss/${PLATFORM}/dddd", 21}, {"'
from ", 7}, {"LD_PRELOAD", 10}, {" cannot be preloaded (", 22}, {"cannot open
shared object file", 30}, {"): ignored.\n", 12}], 7ERROR: ld.so: object
'/sss/${PLATFORM}/dddd' from LD_PRELOAD cannot be preloaded (cannot open shared
object file): ignored.

For glibc-2.22:
execve("/bin/cat", ["/bin/cat"], [/* 32 vars */]) = 0
brk(NULL)                               = 0x55f02a3b2000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f410eaec000
readlink("/proc/self/exe", "/usr/bin/cat", 4096) = 12
open("/sss/x86_64/dddd", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or
directory)
writev(2, [{"ERROR: ld.so: object '", 22}, {"/sss/${PLATFORM}/dddd", 21}, {"'
from ", 7}, {"LD_PRELOAD", 10}, {" cannot be preloaded (", 22}, {"cannot open
shared object file", 30}, {"): ignored.\n", 12}], 7ERROR: ld.so: object
'/sss/${PLATFORM}/dddd' from LD_PRELOAD cannot be preloaded (cannot open shared
object file): ignored.
) = 124

Version 2.22 correctly expand $PLATFORM and attempts to load
"/sss/x86_64/dddd", as expected

Version 2.26 instead tried to openat file with empty name:
openat(AT_FDCWD, "", O_RDONLY|O_CLOEXEC)

I think that problem is GLRO(dl_platform) == NULL.

How it came to be?
File elf/dl-sysdep.c
function _dl_sysdep_start set PLATFORM at line 156:
      case AT_PLATFORM:                                                         
       GLRO(dl_platform) = (void *) av->a_un.a_val;                            
       break;    

But after that at line 231 calls DL_PLATFORM_INIT
#ifdef DL_PLATFORM_INIT                                                         
  DL_PLATFORM_INIT;                                                             
#endif 

DL_PLATFORM_INIT defined to dl_platform_init();

File sysdeps/x86_64/dl-machine.h, line 240
static inline void __attribute__ ((unused))                                     
dl_platform_init (void)                                                         
{                                                                               
#if IS_IN (rtld)                                                                
  /* init_cpu_features has been called early from __libc_start_main in          
     static executable.  */                                                     
  init_cpu_features (&GLRO(dl_x86_cpu_features));                               
#else                                                                           
  if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')                  
    /* Avoid an empty string which would disturb us.  */                        
    GLRO(dl_platform) = NULL;                                                   
#endif                                                                          
}   


function init_cpu_features first of all reset dl_platform:
File sysdeps/x86/cpu-features.c, line 334
  /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  */                 
  GLRO(dl_platform) = NULL;                                                     
  GLRO(dl_hwcap) = 0; 

And then, if special processor detected, set it to "haswell" or "xeon_phi"
But if no special processor detected, dl_platform will remain NULL, not x86_64

File sysdeps/x86/cpu-features.c, line 343
#ifdef __x86_64__                                                               
  if (cpu_features->kind == arch_kind_intel)                                    
    {                                                                           
      if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable)                    
|         && CPU_FEATURES_CPU_P (cpu_features, AVX512CD))                       
|       {                                                                       
|         if (CPU_FEATURES_CPU_P (cpu_features, AVX512ER))                      
|           {                                                                   
|             if (CPU_FEATURES_CPU_P (cpu_features, AVX512PF))                  
|       |       GLRO(dl_platform) = "xeon_phi";                                 
|           }                                                                   
|         else                                                                  
|           {                                                                   
|             if (CPU_FEATURES_CPU_P (cpu_features, AVX512BW)                   
|       |         && CPU_FEATURES_CPU_P (cpu_features, AVX512DQ)                
|       |         && CPU_FEATURES_CPU_P (cpu_features, AVX512VL))               
|       |       GLRO(dl_hwcap) |= HWCAP_X86_AVX512_1;                           
|           }                                                                   
|       }                                                                       

      if (GLRO(dl_platform) == NULL                                             
|         && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable)                    
|         && CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable)                     
|         && CPU_FEATURES_CPU_P (cpu_features, BMI1)                            
|         && CPU_FEATURES_CPU_P (cpu_features, BMI2)                            
|         && CPU_FEATURES_CPU_P (cpu_features, LZCNT)                           
|         && CPU_FEATURES_CPU_P (cpu_features, MOVBE)                           
|         && CPU_FEATURES_CPU_P (cpu_features, POPCNT))                         
|       GLRO(dl_platform) = "haswell";                                          
    }                                                                           
#else

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]