MCPcopy Create free account
hub / github.com/benjojo/hot-clone / writeBitFieldMasks

Method writeBitFieldMasks

sys/unix/linux/mkall.go:446–490  ·  view source on GitHub ↗
(bin *elf.File, out io.Writer)

Source from the content-addressed store, hash-verified

444}
445
446func (t *target) writeBitFieldMasks(bin *elf.File, out io.Writer) error {
447 symbols, err := bin.Symbols()
448 if err != nil {
449 return fmt.Errorf("getting ELF symbols: %v", err)
450 }
451 var masksSym *elf.Symbol
452
453 for _, sym := range symbols {
454 if sym.Name == "masks" {
455 masksSym = &sym
456 }
457 }
458
459 if masksSym == nil {
460 return errors.New("could not find the 'masks' symbol in ELF symtab")
461 }
462
463 dataSection := bin.Section(".data")
464 if dataSection == nil {
465 return errors.New("ELF file has no .data section")
466 }
467
468 data, err := dataSection.Data()
469 if err != nil {
470 return fmt.Errorf("could not read .data section: %v\n", err)
471 }
472
473 var bo binary.ByteOrder
474 if t.BigEndian {
475 bo = binary.BigEndian
476 } else {
477 bo = binary.LittleEndian
478 }
479
480 // 64 bit masks of type uint64 are stored in the data section starting at masks.Value.
481 // Here we are running on AMD64, but these values may be big endian or little endian,
482 // depending on target architecture.
483 for i := uint64(0); i < 64; i++ {
484 off := masksSym.Value + i*8
485 // Define each mask in native by order, so as to match target endian.
486 fmt.Fprintf(out, "#define BITFIELD_MASK_%d %dULL\n", i, bo.Uint64(data[off:off+8]))
487 }
488
489 return nil
490}
491
492// makes the zsysnum_linux_$GOARCH.go file
493func (t *target) makeZSysnumFile() error {

Callers 1

makeABIHeadersMethod · 0.95

Calls 1

Uint64Method · 0.65

Tested by

no test coverage detected