You can have a simple wrapper script to colorize ld output.
I have the following script saved as /usr/local/bin/ld which assumes that the real ld is at /usr/bin/ld.
Now I can change my PATH to point to this directory:
export PATH="/usr/local/bin:${PATH}"
Save as /usr/local/bin/ld and do chmod +x /usr/local/bin/ld
#!/usr/bin/env python3 import subprocess import sys import re RED = '\033[91m' GREEN = '\033[92m' ENDC = '\033[0m' def colorize_output(line): pattern = r'([\/\w\.-]+):(\d+)' colored_line = re.sub(pattern, RED + r'\1' + ENDC + ':' + GREEN + r'\2' + ENDC, line) return colored_line def run_ld(args): process = subprocess.Popen(['/usr/bin/ld'] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while True: output = process.stdout.readline() if not output and process.poll() is not None: break if output: print(colorize_output(output.decode()), end='') while True: output = process.stderr.readline() if not output and process.poll() is not None: break if output: print(colorize_output(output.decode()), end='') return process.poll() if __name__ == '__main__': # Pass all arguments to the ld command exit_code = run_ld(sys.argv[1:]) sys.exit(exit_code)
The only thing is that this script would first print stderr and then stdout.
A more sophisticated script could scan the path to find the right ld.