libsframe: add the SFrame library

libsframe is a library that allows you to:
- decode a .sframe section
- probe and inspect a .sframe section
- encode (and eventually write) a .sframe section.

This library is currently being used by the linker, readelf, objdump.
This library will also be used by the SFrame unwinder which is still
to be upstream'd.

The file include/sframe-api.h defines the user-facing APIs for decoding,
encoding and probing .sframe sections. A set of error codes together
with their error message strings are also defined.

Endian flipping is performed automatically at read and write time, if
cross-endianness is detected.

ChangeLog:

	* Makefile.def: Add libsframe as new module with its
	dependencies.
	* Makefile.in: Regenerated.
	* binutils/Makefile.am: Add libsframe.
	* binutils/Makefile.in: Regenerated.
	* configure: Regenerated
	* configure.ac: Add libsframe to host_libs.
	* libsframe/Makefile.am: New file.
	* libsframe/Makefile.in: New file.
	* libsframe/aclocal.m4: New file.
	* libsframe/config.h.in: New file.
	* libsframe/configure: New file.
	* libsframe/configure.ac: New file.
	* libsframe/sframe-error.c: New file.
	* libsframe/sframe-impl.h: New file.
	* libsframe/sframe.c: New file.

include/ChangeLog:

	* sframe-api.h: New file.

testsuite/ChangeLog:

	* libsframe/testsuite/Makefile.am: New file.
	* libsframe/testsuite/Makefile.in: Regenerated.
	* libsframe/testsuite/libsframe.decode/Makefile.am: New
	  file.
	* libsframe/testsuite/libsframe.decode/Makefile.in:
	  Regenerated.
	* libsframe/testsuite/libsframe.decode/decode.exp: New file.
	* libsframe/testsuite/libsframe.encode/Makefile.am:
	  Likewise.
	* libsframe/testsuite/libsframe.encode/Makefile.in:
	  Regenerated.
	* libsframe/testsuite/libsframe.encode/encode.exp: New file.
	* libsframe/testsuite/libsframe.encode/encode-1.c: Likewise.
	* libsframe/testsuite/libsframe.decode/be-flipping.c: Likewise.
	* libsframe/testsuite/libsframe.decode/frecnt-1.c: Likewise.
	* libsframe/testsuite/libsframe.decode/frecnt-2.c: Likewise.
	* libsframe/testsuite/libsframe.decode/DATA-BE: New file.
	* libsframe/testsuite/libsframe.decode/DATA1: Likewise.
	* libsframe/testsuite/libsframe.decode/DATA2: Likewise.
This commit is contained in:
Weimin Pan
2022-11-15 15:06:59 -08:00
committed by Indu Bhagat
parent dc56ee029e
commit 19e559f1c9
30 changed files with 21577 additions and 7 deletions

View File

@ -0,0 +1,99 @@
/* frecnt-1.c -- Test for decoder in libsframe.
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "sframe-api.h"
/* DejaGnu should not use gnulib's vsnprintf replacement here. */
#undef vsnprintf
#include <dejagnu.h>
/*
* SFrame info from the following source (1 fde 4 fres):
* static int cnt;
* int main() { cnt++; return (cnt); }
*/
#define DATA "DATA1"
int
main (void)
{
sframe_decoder_ctx *dctx = NULL;
uint32_t nfres, fsize;
int32_t fstart;
unsigned char finfo;
int err = 0;
FILE *fp;
struct stat st;
char *sf_buf;
size_t sf_size;
#define TEST(name, cond) \
do \
{ \
if (cond) \
pass (name); \
else \
fail (name); \
} \
while (0)
/* Test Setup. */
fp = fopen (DATA, "r");
if (fp == NULL)
goto setup_fail;
if (fstat (fileno (fp), &st) < 0)
{
perror ("fstat");
fclose (fp);
goto setup_fail;
}
sf_buf = malloc (st.st_size);
if (sf_buf == NULL)
{
perror ("malloc");
goto setup_fail;
}
/* Execute tests. */
sf_size = fread (sf_buf, 1, st.st_size, fp);
fclose (fp);
TEST ("frecnt-1: Read data", sf_size != 0);
dctx = sframe_decode (sf_buf, sf_size, &err);
TEST ("frecnt-1: Decoder setup", dctx != NULL);
unsigned int fde_cnt = sframe_decoder_get_num_fidx (dctx);
TEST ("frecnt-1: Decoder FDE count", fde_cnt == 1);
err = sframe_decoder_get_funcdesc (dctx, 0, &nfres, &fsize, &fstart, &finfo);
TEST ("frecnt-1: Decoder get FDE", err == 0);
TEST ("frecnt-1: Decoder FRE count", nfres == 4);
sframe_decoder_free (&dctx);
return 0;
setup_fail:
sframe_decoder_free (&dctx);
fail ("frecnt-1: Test setup");
return 1;
}