<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/153772>153772</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Duplicate module listing when zero page is mapped
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nevesnunes
      </td>
    </tr>
</table>

<pre>
    # Description

When debugging a target with a memory mapping loaded in the zero page, the module has a duplicated listing at the start of the zero page.

Some actions, such as loading symbols, will throw errors due to matching multiple (duplicated) modules.

# Steps to reproduce

Source file `a.c`:
```c
int main() {
    return 0;
}
```

Linker script `a.ld`:
```ld
OUTPUT_FORMAT(elf64-x86-64)

MEMORY
{
    ram (rw) : ORIGIN = 0x100, LENGTH = 0x40000
    rom (rx) : ORIGIN = 0x400100, LENGTH = 0x40000
}

SECTIONS
{
    .data : { FILL(0x00) . += 1K; } > ram
 .text : { *(.text) } > rom

    /DISCARD/ : { *(.comment) *(.eh_frame*) }
}
```

`Dockerfile`: 
```Dockerfile
FROM debian:bookworm-20250811-slim
RUN apt-get -y update \
    && apt-get install -y gnupg lsb-release software-properties-common wget \
    && wget https://apt.llvm.org/llvm.sh \
    && chmod +x /llvm.sh \
    && /llvm.sh 20
```

Set minimum virtual address to allow mapping zero page, compile, and debug:
```sh
echo 0 | sudo tee /proc/sys/vm/mmap_min_addr

clang-20 -O0 -static -nostdlib -c a.c
ld a.o -T a.ld --build-id
lldb-20 a.out --one-line 'process launch --stop-at-entry' --one-line 'image list' --one-line 'image dump sections a.out'
```

# Current behaviour

```
(lldb) target create "a.out"
Current executable set to '/share/a.out' (x86_64).
(lldb) process launch --stop-at-entry
Process 278 launched: '/share/a.out' (x86_64)
(lldb) image list
[  0] CF0C15EC-96E1-0F70-F2D9-8F6BB9CC9491-4BA4B4D4 0x0000000000000000 /share/a.out
[  1] CF0C15EC-96E1-0F70-F2D9-8F6BB9CC9491-4BA4B4D4 0x0000000000000000 /share/a.out
[  2] 2B3312B1-A6A1-6808-B9C9-5675682C1430-19E065E3 0x00007ffff7ffd000 [vdso] (0x00007ffff7ffd000)
(lldb) image dump sections a.out
Sections for '/share/a.out' (x86_64):
  SectID             Type                   Load Address                             Perm File Off.  File Size  Flags Section Name
  ------------------ ---------------------- ---------------------------------------  ---- ---------- ---------- ---------- ----------------------------
  0xffffffffffffffff container [0x0000000000000000-0x0000000000000424)  rw-  0x00001100 0x00000024 0x00000000 a.out.PT_LOAD[0]
  0x0000000000000001 regular [0x0000000000000000-0x0000000000000024)  r--  0x00001100 0x00000024 0x00000002 a.out.PT_LOAD[0]..note.gnu.build-id
  0x0000000000000002 zero-fill              [0x0000000000000024-0x0000000000000424)  rw- 0x00001124 0x00000000 0x00000003 a.out.PT_LOAD[0]..data
  0xfffffffffffffffe container              [0x0000000000400000-0x000000000040000f)  r-x 0x00002100 0x0000000f 0x00000000 a.out.PT_LOAD[1]
  0x0000000000000003 code [0x0000000000400000-0x000000000040000f)  r-x  0x00002100 0x0000000f 0x00000006 a.out.PT_LOAD[1]..text
  0x0000000000000004 elf-symbol-table                                                --- 0x00002110 0x00000048 0x00000000 a.out..symtab
  0x0000000000000005 regular ---  0x00002158 0x0000000a 0x00000000 a.out..strtab
  0x0000000000000006 regular ---  0x00002162 0x0000003a 0x00000000 a.out..shstrtab
```

Attempting to load symbols and sections:

```
(lldb) target symbols add a.out
error: multiple modules match symbol file '/share/a.out', use the --uuid option to resolve the ambiguity.

(lldb) target modules load --uuid CF0C15EC-96E1-0F70-F2D9-8F6BB9CC9491-4BA4B4D4 .data 0x900000
/share/a.out
/share/a.out
error: multiple modules match uuid=CF0C15EC-96E1-0F70-F2D9-8F6BB9CC9491-4BA4B4D4:
```

If we update `a.ld` to set an origin after the zero page:

```diff
-    ram (rw) : ORIGIN = 0x100, LENGTH = 0x40000
+    ram (rw) : ORIGIN = 0x1100, LENGTH = 0x40000
```

We only get a single listing for this module:

```
# lldb-20 a.0x001100.out --one-line 'process launch --stop-at-entry' --one-line 'image list' --one-line 'image dump sections a.0x001100.out'

(lldb) target create "a.0x001100.out"
Current executable set to '/share/a.0x001100.out' (x86_64).
(lldb) process launch --stop-at-entry
Process 301 launched: '/share/a.0x001100.out' (x86_64)
(lldb) image list
[  0] 602155C1-95B3-20A7-A847-61D93C19D0D3-BD2685ED 0x0000000000001100 /share/a.0x001100.out
[  1] 2B3312B1-A6A1-6808-B9C9-5675682C1430-19E065E3 0x00007ffff7ffd000 [vdso] (0x00007ffff7ffd000)
(lldb) image dump sections a.0x001100.out
Sections for '/share/a.0x001100.out' (x86_64):
  SectID Type                   Load Address                             Perm File Off.  File Size  Flags      Section Name
  ------------------ ---------------------- ---------------------------------------  ---- ---------- ---------- ---------- ----------------------------
 0xffffffffffffffff container [0x0000000000001100-0x0000000000001524)  rw-  0x00001100 0x00000024 0x00000000 a.0x001100.out.PT_LOAD[0]
  0x0000000000000001 regular [0x0000000000001100-0x0000000000001124)  r--  0x00001100 0x00000024 0x00000002 a.0x001100.out.PT_LOAD[0]..note.gnu.build-id
  0x0000000000000002 zero-fill              [0x0000000000001124-0x0000000000001524)  rw- 0x00001124 0x00000000 0x00000003 a.0x001100.out.PT_LOAD[0]..data
 0xfffffffffffffffe container [0x0000000000400100-0x000000000040010f)  r-x  0x00002100 0x0000000f 0x00000000 a.0x001100.out.PT_LOAD[1]
  0x0000000000000003 code [0x0000000000400100-0x000000000040010f)  r-x  0x00002100 0x0000000f 0x00000006 a.0x001100.out.PT_LOAD[1]..text
  0x0000000000000004 elf-symbol-table                                                --- 0x00002110 0x00000048 0x00000000 a.0x001100.out..symtab
  0x0000000000000005 regular                                                         --- 0x00002158 0x0000000a 0x00000000 a.0x001100.out..strtab
  0x0000000000000006 regular                                                         --- 0x00002162 0x0000003a 0x00000000 a.0x001100.out..shstrtab
```

# Expected behaviour

In either case, we should have a single listing for the loaded module, or a workaround that allows us to desambiguate a module by index.

# Context

```
# uname -a
Linux 888ad4154b71 6.1.0-35-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.137-1 (2025-05-07) x86_64 GNU/Linux

# clang-20 --version
Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-20/bin

# ld --version
GNU ld (GNU Binutils for Debian) 2.40

# lldb-20 --version
lldb version 20.1.8
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWUtz6yoS_jVk04ULIevhRRayFZ9Jzcmjkpy6dVcpLCGLOZJQAYqdu7i_fQokO37FSe6j5g6VhYOa7o9uaL4GprVYNpxfomCKgvSCdaaU6rLhL1w3XcP1xULmr5eI-pBynSnRGiEbRBJEkl9K3kDOF91yKZolMDBMLbmBlTAlMKh5LdUr1Kxt7edKspznIBowJYffuJLQsiVHdOY6apl3FYeSaWCQd20lMmZ4DpXQxmk3TkwbpgzIYl_JqAf0KGsOLLMItdWru6wEpp1pq0O_1gtZuU8rUVVgSiVXwJWSSkPecTASamay0grXXWVEW3FANH7Dg-hkgKoHo9Y1j4a32o5WvFUy7zK-AdSpjEMhrJqQsFGGQoJ8Nywk_V-GSCIaAzUTDaKxNYCiKSIJAIDiplMNEOTbHhSluyN7G99F85Mr6GPTW6nyYzNVjkhy9-Pp_sfT8_zu4SZ5QjTmVRGO8ToOcThGdNIrvLm6uXv41ZnbwmC1dYNaOXR-AncP19-ubwH5KZC1R4h16fer229P_xr6xoQQshkt-9Hrk6PHhJxTMMyZJI9Xs6fru9vHPWCjnBnmdKJoCvPr798Rjcna6pvACBCdWm3ev5E_BRSlgPwrOxk7emT42myHIpogGru-PgKDrKx769YYovP0-nGWPKSIzg9HZrKuedMP7nt4-VwoVnP3r1P5XghRSFKZ_eTKLpQ-dLArtfORJPOHuxu76wRrkJ8spPy5kqrGlNCAxJ6HdSUs5ocft8Bag-2GxK_QtTk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