labath requested changes to this revision.
labath added a comment.
This revision now requires changes to proceed.

If I correctly understand what this is doing, then I don't think it's a good 
idea. The base of an (elf) shared library does not have to be mapped 
executable. These are the mappings I get for a trivial hello world program (no 
mmapping of libraries or anything) on my linux machine:

  00400000-00401000 r--p 00000000 fd:01 2838574                            
/tmp/l/a.out
  00401000-00402000 r-xp 00001000 fd:01 2838574                            
/tmp/l/a.out
  00402000-00403000 r--p 00002000 fd:01 2838574                            
/tmp/l/a.out
  00403000-00404000 r--p 00002000 fd:01 2838574                            
/tmp/l/a.out
  00404000-00405000 rw-p 00003000 fd:01 2838574                            
/tmp/l/a.out
  020fb000-0211c000 rw-p 00000000 00:00 0                                  
[heap]
  7fe4f5d87000-7fe4f5da9000 r--p 00000000 fd:01 2738932                    
/lib64/libc-2.31.so
  7fe4f5da9000-7fe4f5ef3000 r-xp 00022000 fd:01 2738932                    
/lib64/libc-2.31.so
  7fe4f5ef3000-7fe4f5f3d000 r--p 0016c000 fd:01 2738932                    
/lib64/libc-2.31.so
  7fe4f5f3d000-7fe4f5f41000 r--p 001b5000 fd:01 2738932                    
/lib64/libc-2.31.so
  7fe4f5f41000-7fe4f5f43000 rw-p 001b9000 fd:01 2738932                    
/lib64/libc-2.31.so
  ...

Here, the correct base of a.out is 0x00400000 and the libc base is 
0x7fe4f5d87000. But this patch would make them be detected as 0x00401000 and 
0x7fe4f5da9000, respectively.

This behavior is controlled by the `-z (no)separate-code`. My machine has 
`separate-code` as default, but that setting may not be universal, so you may 
need to pass this flag explicitly to reproduce this. For reference, these are 
the mappings I get when compiling a.out with `-z noseparate-code` (libc 
mappings remain unchanged, of course):

  00400000-00401000 r-xp 00000000 fd:01 2838574                            
/tmp/l/a.out
  00401000-00402000 r--p 00000000 fd:01 2838574                            
/tmp/l/a.out
  00402000-00403000 rw-p 00001000 fd:01 2838574                            
/tmp/l/a.out

It sounds like we need a better heuristic. How about "the number of consecutive 
mappings with the same name"? User mmapping code is likely going to map the 
library in a single chunk, but the dynamic linker will typically create 
multiple mappings (even a trivial executable can have five), so it seems like 
picking the longest sequence could work...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86375/new/

https://reviews.llvm.org/D86375

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to