It is indeed important to differentiate the drug in question and the individual and the intention for using the drug and the way it is taken, temporally.
Painkillers – or analgesics – come in a wide variety, be that in the form of opioids, cannabinoids, NSAIDs, ion-channel_modulators, myorelaxants or uncategorised drugs like ketamine. Not all are usually administered orally or even effective that way, by far not all are even available prescription free. As should become clear by now, "a general guideline" is almost impossible to formulate.
You have to inquire about one specific drug in question. And even then it will be complicated and our picture about every single one of all those drugs is still evolving and however detailed it may seem, incomplete. Follow the advice given on the leaflet, by your pharmacist and doctor.
Taking the example of cannabinoids, it is common knowledge that a full stomach will delay the effects of the active ingredients, but the simultaneous ingestion of a little bit of fat will increase the absorption of them. The more interesting molecules are all lipophilic and quite waste to digest in isolation.
It will be also a quite different story if we are talking about a one-time paracetamol administration or a long term course of aspirin, to name just one example pair.
The possible side-effects and interactions are different for each drug in question and each individual will fall on a different place of the scale of possible consequences. That does still not take into account the different foods that might interact with the drugs and the stomachs content.
Some important problems to keep an eye on when reading the accompanying leaflet are for example time the drug is in the stomach (gastric emptying) or the pH with the drug and with or with food (buffering).
Prostaglandins, NSAIDs, and Gastric Mucosal Protection: Why Doesn’t the Stomach Digest Itself? (Physiol Rev 88: 1547–1565, 2008; doi:10.1152/physrev.00004.2008.)
Since both other answers are basically correct on their own, I will only add some details that wouldn't fit into comments.
Concernig absorption rates:
Absorption of acetylsalicylic acid from unbuffered and buffered gastric contents and Gastrointestinal Factors in Aspirin Absorption: A Quantitative Study but that is in contrast to Absorption of aspirin from the stomach in man, Influence of food on aspirin absorption from tablets and buffered solutions, Kinetics of aspirin absorption following oral administration of six aqueous solutions with different buffer capacities.
The most common side-effect of taking drugs orally is probably an upset stomach, but one of the more important effects might be actual bleeding, even with low dose aspirin: Risk of upper gastrointestinal bleeding associated with use of low-dose aspirin
While the already mentioned COX inhibition is a problem in itself, many natural substances occurring naturally in food are also known to exhibit this action, very probably increasing the risk if even ever so slightly. Substances that might act in this way:
Therefore, caution should be exercised if combining aspirin with any "natural" supplements with COX-2-inhibiting properties, such as garlic extracts, curcumin, bilberry, pine bark, ginkgo, fish oil, resveratrol, genistein, quercetin, resorcinol, and others.
As a personal anecdote I might also add saffron to the list of side-effects enhancers.
But look how aspirin and paracetamol differ in their pharmocokinetics.
These factors would modulate the kinetics in the inflammatory focus, thereby prolonging the therapeutic action of the drug beyond that expected based on analysis of plasma pharmacokinetics. However, ion trapping also results in acidic compounds achieving high concentrations in the stomach wall and kidney, in which blockade of prostanoid synthesis causes the typical organ toxicity elicited by these compounds. Due to their lack of acidic structure, other COX inhibitors, such as dipyrone and paracetamol, are distributed homogenously throughout the body at therapeutic doses and induce analgesia, but induce no or very slight anti-inflammatory effects. This is partly due to their low concentration in inflamed tissues. (p14)
All NSAIDs approved by the US Food and Drug Administration carry the same boxed warning for cardiovascular and gastrointestinal risk. These state “NSAIDs may cause an increased risk of serious cardiovascular thrombotic events, myocardial infarction, and stroke, which can be fatal. This risk may increase with duration of use. Patients with cardiovascular disease or risk factors for cardiovascular disease may be at greater risk” and “NSAIDs cause an increased risk of serious gastrointestinal adverse events including bleeding, ulceration, and perforation of the stomach or intestines, which can be fatal. These events can occur at any time during use and without warning symptoms. Elderly patients are at greater risk for serious gastrointestinal events,” respectively. (p37/8)
Angel Lanas (Ed): "NSAIDs and Aspirin. Recent Advances and Implications for Clinical Management", Springer, 2016. DOI 10.1007/978-3-319-33889-7