URI:
       libmach: Add findseg() - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 52cf2e9986d52e8e812a30b94dc118dabb1aea1f
   DIR parent ece7fade7d459523af266428e95b4f587a2f0ba9
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Mon,  5 Jan 2026 22:22:18 +0100
       
       libmach: Add findseg()
       
       This function returns the segment index in the map.  This function is
       mainly designed to be used in elf where there is a difference between
       sections and segments.
       
       Diffstat:
         M include/scc/bits/scc/mach.h         |       1 +
         M src/libmach/Makefile                |       1 +
         A src/libmach/findseg.c               |      21 +++++++++++++++++++++
       
       3 files changed, 23 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/include/scc/bits/scc/mach.h b/include/scc/bits/scc/mach.h
       @@ -162,6 +162,7 @@ int pc2line(Obj *, unsigned long long, char *, int *);
        int rebase(Obj *, int, unsigned long long);
        
        int findsec(Map *, char *);
       +int findseg(Map *, unsigned long long);
        
        Symbol *getsym(Obj *, int *, Symbol *);
        Symbol *setsym(Obj *, int *, Symbol *);
   DIR diff --git a/src/libmach/Makefile b/src/libmach/Makefile
       @@ -16,6 +16,7 @@ OBJS =\
                delmap.o\
                delobj.o\
                findsec.o\
       +        findseg.o\
                getindex.o\
                getsec.o\
                getsym.o\
   DIR diff --git a/src/libmach/findseg.c b/src/libmach/findseg.c
       @@ -0,0 +1,21 @@
       +#include <stdio.h>
       +#include <string.h>
       +
       +#include <scc/mach.h>
       +
       +#include "libmach.h"
       +
       +int
       +findseg(Map *map, unsigned long long addr)
       +{
       +        int i;
       +        Mapsec *seg;
       +
       +        for (i = 0; i < map->nseg; ++i) {
       +                seg = &map->seg[i];
       +                if (seg->used && seg->sec.base == addr)
       +                        return i;
       +        }
       +
       +        return -1;
       +}