1*5ac3bc71Schristos.\" $NetBSD: elf_flagdata.3,v 1.6 2024/03/03 17:37:33 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2006-2008,2011 Joseph Koshy. All rights reserved. 49dd9d0cfSchristos.\" 59dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 69dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 79dd9d0cfSchristos.\" are met: 89dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 99dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 109dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 119dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 129dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 139dd9d0cfSchristos.\" 149dd9d0cfSchristos.\" This software is provided by Joseph Koshy ``as is'' and 159dd9d0cfSchristos.\" any express or implied warranties, including, but not limited to, the 169dd9d0cfSchristos.\" implied warranties of merchantability and fitness for a particular purpose 179dd9d0cfSchristos.\" are disclaimed. in no event shall Joseph Koshy be liable 189dd9d0cfSchristos.\" for any direct, indirect, incidental, special, exemplary, or consequential 199dd9d0cfSchristos.\" damages (including, but not limited to, procurement of substitute goods 209dd9d0cfSchristos.\" or services; loss of use, data, or profits; or business interruption) 219dd9d0cfSchristos.\" however caused and on any theory of liability, whether in contract, strict 229dd9d0cfSchristos.\" liability, or tort (including negligence or otherwise) arising in any way 239dd9d0cfSchristos.\" out of the use of this software, even if advised of the possibility of 249dd9d0cfSchristos.\" such damage. 259dd9d0cfSchristos.\" 263f622274Sjkoshy.\" Id: elf_flagdata.3 3954 2022-03-12 12:07:16Z jkoshy 279dd9d0cfSchristos.\" 28c5261b83Sjkoshy.Dd June 12, 2019 299dd9d0cfSchristos.Dt ELF_FLAGDATA 3 30c5261b83Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 329dd9d0cfSchristos.Nm elf_flagarhdr , 339dd9d0cfSchristos.Nm elf_flagdata , 349dd9d0cfSchristos.Nm elf_flagehdr , 359dd9d0cfSchristos.Nm elf_flagelf , 369dd9d0cfSchristos.Nm elf_flagphdr , 379dd9d0cfSchristos.Nm elf_flagscn , 389dd9d0cfSchristos.Nm elf_flagshdr 39c5261b83Sjkoshy.Nd manipulate flags associated with ELF data structures 409dd9d0cfSchristos.Sh LIBRARY 419dd9d0cfSchristos.Lb libelf 429dd9d0cfSchristos.Sh SYNOPSIS 439dd9d0cfSchristos.In libelf.h 449dd9d0cfSchristos.Ft "unsigned int" 459dd9d0cfSchristos.Fn elf_flagarhdr "Elf_Arhdr *arhdr" "Elf_Cmd cmd" "unsigned int flags" 469dd9d0cfSchristos.Ft "unsigned int" 479dd9d0cfSchristos.Fn elf_flagdata "Elf_Data *data" "Elf_Cmd cmd" "unsigned int flags" 489dd9d0cfSchristos.Ft "unsigned int" 499dd9d0cfSchristos.Fn elf_flagehdr "Elf *elf" "Elf_Cmd cmd" "unsigned int flags" 509dd9d0cfSchristos.Ft "unsigned int" 519dd9d0cfSchristos.Fn elf_flagelf "Elf *elf" "Elf_Cmd cmd" "unsigned int flags" 529dd9d0cfSchristos.Ft "unsigned int" 539dd9d0cfSchristos.Fn elf_flagphdr "Elf *elf" "Elf_Cmd cmd" "unsigned int flags" 549dd9d0cfSchristos.Ft "unsigned int" 559dd9d0cfSchristos.Fn elf_flagscn "Elf_Scn *scn" "Elf_Cmd cmd" "unsigned int flags" 569dd9d0cfSchristos.Ft "unsigned int" 579dd9d0cfSchristos.Fn elf_flagshdr "Elf_Scn *scn" "Elf_Cmd cmd" "unsigned int flags" 589dd9d0cfSchristos.Sh DESCRIPTION 599dd9d0cfSchristosThese functions are used to query, set or reset flags on data 609dd9d0cfSchristosstructures associated with an ELF file. 619dd9d0cfSchristos.Pp 629dd9d0cfSchristosArguments 633f622274Sjkoshy.Fa arhdr , 643f622274Sjkoshy.Fa data , 653f622274Sjkoshy.Fa elf 669dd9d0cfSchristosand 673f622274Sjkoshy.Fa scn 689dd9d0cfSchristosdenote the data structures whose flags need to be changed. 699dd9d0cfSchristosThese values should have been returned by prior calls to 70c5261b83Sjkoshyfunctions in the 71c5261b83Sjkoshy.Xr elf 3 72c5261b83SjkoshyAPI set: 739dd9d0cfSchristos.Bl -bullet -compact 749dd9d0cfSchristos.It 759dd9d0cfSchristosArgument 763f622274Sjkoshy.Fa arhdr 779dd9d0cfSchristosshould have been returned by a prior call to 789dd9d0cfSchristos.Xr elf_getarhdr 3 . 799dd9d0cfSchristos.It 809dd9d0cfSchristosArgument 813f622274Sjkoshy.Fa data 829dd9d0cfSchristosshould have been returned by a prior call to one of 839dd9d0cfSchristos.Xr elf_newdata 3 , 849dd9d0cfSchristos.Xr elf_getdata 3 859dd9d0cfSchristosor 869dd9d0cfSchristos.Xr elf_rawdata 3 . 879dd9d0cfSchristos.It 889dd9d0cfSchristosArgument 893f622274Sjkoshy.Fa elf 909dd9d0cfSchristosshould have been allocated by a prior call to one of 919dd9d0cfSchristos.Xr elf_begin 3 929dd9d0cfSchristosor 939dd9d0cfSchristos.Xr elf_memory 3 . 949dd9d0cfSchristos.It 959dd9d0cfSchristosArgument 963f622274Sjkoshy.Fa scn 979dd9d0cfSchristosshould have been returned by a prior call to one of 989dd9d0cfSchristos.Xr elf_getscn 3 , 999dd9d0cfSchristos.Xr elf_newscn 3 1009dd9d0cfSchristosor 1019dd9d0cfSchristos.Xr elf_nextscn 3 . 1029dd9d0cfSchristos.El 103c5261b83SjkoshyThese values are allowed to be 104c5261b83Sjkoshy.Dv NULL 105c5261b83Sjkoshyto simplify error handling in application code. 1069dd9d0cfSchristos.Pp 1079dd9d0cfSchristosArgument 1083f622274Sjkoshy.Fa cmd 1099dd9d0cfSchristosmay have the following values: 1109dd9d0cfSchristos.Bl -tag -width ELF_C_SET 1119dd9d0cfSchristos.It Dv ELF_C_CLR 1129dd9d0cfSchristosThe argument 1133f622274Sjkoshy.Fa flags 1149dd9d0cfSchristosspecifies the flags to be cleared. 1159dd9d0cfSchristos.It Dv ELF_C_SET 1169dd9d0cfSchristosThe argument 1173f622274Sjkoshy.Fa flags 1189dd9d0cfSchristosspecifies the flags to be set. 1199dd9d0cfSchristos.El 1209dd9d0cfSchristos.Pp 1219dd9d0cfSchristosThe argument 1223f622274Sjkoshy.Fa flags 1239dd9d0cfSchristosis allowed to have the following flags set: 1249dd9d0cfSchristos.Bl -tag -width ELF_F_ARCHIVE_SYSV 1259dd9d0cfSchristos.It Dv ELF_F_ARCHIVE 1269dd9d0cfSchristosThis flag is only valid with the 1279dd9d0cfSchristos.Fn elf_flagelf 1289dd9d0cfSchristosAPI. 1299dd9d0cfSchristosIt informs the library that the application desires to create an 1309dd9d0cfSchristos.Xr ar 1 1319dd9d0cfSchristosarchive. 1329dd9d0cfSchristosArgument 1333f622274Sjkoshy.Fa elf 1349dd9d0cfSchristosshould have been opened for writing using the 1359dd9d0cfSchristos.Dv ELF_C_WRITE 1369dd9d0cfSchristoscommand to function 1379dd9d0cfSchristos.Fn elf_begin . 1389dd9d0cfSchristos.It Dv ELF_F_ARCHIVE_SYSV 1399dd9d0cfSchristosThis flag is used in conjunction with the 1409dd9d0cfSchristos.Dv ELF_F_ARCHIVE 1419dd9d0cfSchristosflag to indicate that library should create archives that conform 1429dd9d0cfSchristosto System V layout rules. 1439dd9d0cfSchristosThe default is to create BSD style archives. 1449dd9d0cfSchristos.It Dv ELF_F_DIRTY 1459dd9d0cfSchristosMark the associated data structure as needing to be written back 1469dd9d0cfSchristosto the underlying file. 1479dd9d0cfSchristosA subsequent call to 1489dd9d0cfSchristos.Xr elf_update 3 1499dd9d0cfSchristoswill resynchronize the library's internal data structures. 1509dd9d0cfSchristos.It Dv ELF_F_LAYOUT 1519dd9d0cfSchristosThis flag is only valid with the 1529dd9d0cfSchristos.Fn elf_flagelf 1539dd9d0cfSchristosAPI. 1549dd9d0cfSchristosIt informs the library that the application will take 1559dd9d0cfSchristosresponsibility for the layout of the file and that the library is 1569dd9d0cfSchristosnot to insert any padding in between sections. 1579dd9d0cfSchristos.El 1589dd9d0cfSchristos.Pp 1599dd9d0cfSchristosMarking a given data structure as 1609dd9d0cfSchristos.Dq dirty 1619dd9d0cfSchristosaffects all of its contained elements. 1629dd9d0cfSchristosThus marking an ELF descriptor 1633f622274Sjkoshy.Fa elf 1649dd9d0cfSchristoswith 1659dd9d0cfSchristos.Fn elf_flagelf "elf" "ELF_C_SET" "ELF_F_DIRTY" 1669dd9d0cfSchristosmeans that the entire contents of the descriptor are 1679dd9d0cfSchristos.Dq dirty . 1689dd9d0cfSchristos.Pp 1699dd9d0cfSchristosUsing a value of zero for argument 1703f622274Sjkoshy.Fa flags 1719dd9d0cfSchristoswill return the current set of flags for the data structure being 1729dd9d0cfSchristosqueried. 1739dd9d0cfSchristos.Sh RETURN VALUES 1749dd9d0cfSchristosThese functions return the updated flags if successful, or zero if 1759dd9d0cfSchristosan error is detected. 1769dd9d0cfSchristos.Sh COMPATIBILITY 1779dd9d0cfSchristosThe 1789dd9d0cfSchristos.Fn elf_flagarhdr 1799dd9d0cfSchristosfunction and the 1809dd9d0cfSchristos.Dv ELF_F_ARCHIVE 1819dd9d0cfSchristosand 1829dd9d0cfSchristos.Dv ELF_F_ARCHIVE_SYSV 183c5261b83Sjkoshyflags are an extension to the 184c5261b83Sjkoshy.Xr elf 3 185c5261b83SjkoshyAPI. 1869dd9d0cfSchristos.Sh ERRORS 1879dd9d0cfSchristosThese functions may fail with the following errors: 1889dd9d0cfSchristos.Bl -tag -width "[ELF_E_RESOURCE]" 1899dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1909dd9d0cfSchristosAn unsupported value was used for the 1913f622274Sjkoshy.Fa cmd 1929dd9d0cfSchristosargument. 1939dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1949dd9d0cfSchristosArgument 1953f622274Sjkoshy.Fa flags 1969dd9d0cfSchristoshad unsupported flags set. 1979dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1989dd9d0cfSchristosThe argument 1993f622274Sjkoshy.Fa elf 2009dd9d0cfSchristoswas not a descriptor for an ELF object. 2019dd9d0cfSchristos.It Bq Er ELF_E_MODE 2029dd9d0cfSchristosThe 2039dd9d0cfSchristos.Dv ELF_F_ARCHIVE 2049dd9d0cfSchristosflag was used with an ELF descriptor that had not been opened for writing. 2059dd9d0cfSchristos.It Bq Er ELF_E_SEQUENCE 2069dd9d0cfSchristosFunction 2079dd9d0cfSchristos.Fn elf_flagehdr 2089dd9d0cfSchristoswas called without an executable header being allocated. 2099dd9d0cfSchristos.It Bq Er ELF_E_SEQUENCE 2109dd9d0cfSchristosFunction 2119dd9d0cfSchristos.Fn elf_flagphdr 2129dd9d0cfSchristoswas called without a program header being allocated. 2139dd9d0cfSchristos.El 2149dd9d0cfSchristos.Sh SEE ALSO 2159dd9d0cfSchristos.Xr elf 3 , 2169dd9d0cfSchristos.Xr elf32_newehdr 3 , 2179dd9d0cfSchristos.Xr elf32_newphdr 3 , 2189dd9d0cfSchristos.Xr elf64_newehdr 3 , 2199dd9d0cfSchristos.Xr elf64_newphdr 3 , 2209dd9d0cfSchristos.Xr elf_newdata 3 , 2219dd9d0cfSchristos.Xr elf_update 3 , 2229dd9d0cfSchristos.Xr gelf 3 , 2239dd9d0cfSchristos.Xr gelf_newehdr 3 , 2249dd9d0cfSchristos.Xr gelf_newphdr 3 , 2259dd9d0cfSchristos.Xr gelf_update_dyn 3 , 2269dd9d0cfSchristos.Xr gelf_update_move 3 , 2279dd9d0cfSchristos.Xr gelf_update_rel 3 , 2289dd9d0cfSchristos.Xr gelf_update_rela 3 , 2299dd9d0cfSchristos.Xr gelf_update_sym 3 , 2309dd9d0cfSchristos.Xr gelf_update_syminfo 3 231