0

If a DEB package contains a shared library that was built from source code that was generated by flex , /usr/bin/lintian would report

shlib-calls-exit

because of the exit() call in the flex-generated function yy_fatal_error:

static void yy_fatal_error (yyconst char* msg )
{
        (void) fprintf( stderr, "%s\n", msg );
        exit( YY_EXIT_FAILURE );
}

How can I modify the DEB package so that the lintian will stop reporting shlib-calls-exit?

The DEB package makes use of CMake in its build script. The corresponding snippet of CMake source code is

flex_target(scanner lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
bison_target(parser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c) 
add_flex_bison_dependency(scanner parser)
add_library(parse-and-scan SHARED ${FLEX_scanner_OUTPUTS} ${BISON_parser_OUTPUT_SOURCE})

Information about the software versions:

  • flex 2.5.35
  • cmake 2.8.9
  • lintian 2.5.10
  • Linux distribution: Debian Unstable (sid)

About a week ago I posted a similar question to the debian-mentors mailing list

The problem of having an exit() call in the flex generated source code has been brought up on the flex-help mailing list, but that post rendered no answers.

rici
  • 234,347
  • 28
  • 237
  • 341
Erik Sjölund
  • 10,690
  • 7
  • 46
  • 74

1 Answers1

-1

By replacing the exit() call with an abort() call lintian will no more report shlib-calls-exit. CMake could handle this replacement by reading the file lexer.c into a string, then doing text replacement, and then writing the string to the new file lexer_replaced.c (an arbitrary filename).

flex_target(scanner lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
bison_target(parser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c) 
add_flex_bison_dependency(scanner parser)
set(replaced_file ${CMAKE_CURRENT_BINARY_DIR}/lexer_replaced.c)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/replace_exit_with_abort.cmake "
  file(READ ${FLEX_scanner_OUTPUTS} var1)
  string(REPLACE \"exit\\( YY_EXIT_FAILURE \\);\" \"abort();\" var2 \"\${var1}\")
  file(WRITE ${replaced_file} \"\${var2}\")
")
add_custom_command(OUTPUT ${replaced_file}
  COMMAND ${CMAKE_COMMAND} 
  ARGS -P ${CMAKE_CURRENT_BINARY_DIR}/replace_exit_with_abort.cmake
  DEPENDS ${FLEX_scanner_OUTPUTS}
)
add_library(parse-and-scan SHARED ${replaced_file} ${BISON_parser_OUTPUT_SOURCE})

I think this is a workable solution, but the best solution in the long run would be to modify the program flex to always return from its functions instead of sometimes using exit() calls. If an error condition occurs a flex function would then pass this information to the caller by using a different return value.

Erik Sjölund
  • 10,690
  • 7
  • 46
  • 74