| 250 | } |
| 251 | |
| 252 | static int find_program_segment(struct rmod_context *ctx) |
| 253 | { |
| 254 | int i; |
| 255 | int nsegments; |
| 256 | struct parsed_elf *pelf; |
| 257 | Elf64_Phdr *phdr = NULL; |
| 258 | |
| 259 | pelf = &ctx->pelf; |
| 260 | |
| 261 | /* There should only be a single loadable segment. */ |
| 262 | nsegments = 0; |
| 263 | for (i = 0; i < pelf->ehdr.e_phnum; i++) { |
| 264 | if (pelf->phdr[i].p_type != PT_LOAD) |
| 265 | continue; |
| 266 | if (!phdr) |
| 267 | phdr = &pelf->phdr[i]; |
| 268 | nsegments++; |
| 269 | } |
| 270 | |
| 271 | if (nsegments == 0) { |
| 272 | ERROR("No loadable segment found.\n"); |
| 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | INFO("Segment at 0x%0llx, file size 0x%0llx, mem size 0x%0llx.\n", |
| 277 | (long long)phdr->p_vaddr, (long long)phdr->p_filesz, |
| 278 | (long long)phdr->p_memsz); |
| 279 | |
| 280 | ctx->phdr = phdr; |
| 281 | ctx->nsegments = nsegments; |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static int |
| 287 | filter_relocation_sections(struct rmod_context *ctx) |