set test "buildid" set bid_stp $srcdir/$subdir/buildid.stp if {![installtest_p]} { untested $test; return } if {![uprobes_p]} { untested "$test (uprobes)"; return } proc cleanup_handler { verbose } { if { $verbose == 0 } { catch {exec rm -f bid.hex bid.ko bid.stp buildid1.ro buildid2.ro buildid.c buildid.o buildid.ro buildid.x libbid1.so libbid.so } } } proc error_handler { res message } { global verbose if { $res == 0 } { verbose $message 2 fail $message cleanup_handler $verbose return 1 } else { pass $message return 0 } } # Not Shared set bid_srcpath $srcdir/$subdir/buildid.c set res [target_compile $bid_srcpath "[pwd]/buildid.o" object "additional_flags=-g"] if { [error_handler [expr {$res==""}] "buildid.o"] } { return } set res [target_link "buildid.o" "buildid.ro" "-r"] if { [error_handler [expr {$res==""}] "buildid.ro"] } { return } set bid_exepath ./buildid.x set res [target_compile "" $bid_exepath executable "additional_flags=buildid.ro"] if { [error_handler [expr {$res==""}] "$bid_exepath"] } { return } # Check that the build ID exists on this system set bid_check_passed 0 set cmd [concat {/usr/bin/eu-readelf -n $bid_exepath}] eval spawn $cmd expect { -timeout 180 -re {^[^\r\n]*GNU_BUILD_ID[^\r\n]*\r\n} { set bid_check_passed 1 exp_continue } -re {^[^\r\n]*\r\n} { exp_continue } timeout { set bid_check_passed 0 } } catch close if {$bid_check_passed == 0} { untested "Build IDs do not exist on this system" cleanup_handler $verbose return } # Since uprobes.ko may not be prebuilt in the runtime, and we don't yet have a # way to discover the path to the cache-build uprobes.ko, we need to preload # it. This dummy run lets us go through the motions to get uprobes loaded, and # then we don't need to worry about each staprun -u finding its module. # PR13536: it turns out PR5163 makes staprun -u (without /path) impossible, so # stop using it in this test case. Instead we hope and pray and beseech the # almighty spaghetti monster that uprobes stay loaded after the following ditty: spawn stap -m bid $bid_stp $bid_exepath -c /bin/true wait # now alter the build id using objcopy set bid_bid $srcdir/$subdir/buildid.hex system "objcopy --remove-section=.note.gnu.build-id buildid.ro buildid1.ro" system "objcopy --add-section .note.gnu.build-id=$bid_bid buildid1.ro buildid2.ro" set res [target_compile "" $bid_exepath executable "additional_flags=buildid2.ro"] if { [error_handler [expr {$res==""}] "$bid_exepath altered"] } { return } set ok 0 spawn staprun [pwd]/bid.ko -c $bid_exepath expect { -timeout 180 -re {ERROR: Build-id mismatch} { incr ok; exp_continue } timeout { fail "$test (timeout)" } eof { } } catch {close}; catch {wait} error_handler [expr $ok==1] "nonshared build id !ok ($ok)" cleanup_handler $verbose